473,651 Members | 3,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random Number Based on another Cell in Row

6 New Member
Hi,

I have a table with a column in which I would like to generate random numbers. I know how to use the dbms_random function but don't know how I would do what I want to do.

I would like to have the column filled with random numbers that are based on another number in each row.

For example, I have a table with column A and B where A is filled with various number. I want column B to be random numbers that are +or- whatever number is in column A. So say a row in column A is 5, B should be a random number with boundary 5 +or- 2.

Is there a way to do this?

Thanks!
Jan 9 '08 #1
4 2839
debasisdas
8,127 Recognized Expert Expert
Try to write a trigger on insert or update event of data on column A and update columnb B accordingly.
You can also put the logic in a procedure and call in the triggering event.
Jan 10 '08 #2
amitpatel66
2,367 Recognized Expert Top Contributor
check this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1* update t1 set b = dbms_random.value(a,a-2)
  5. SQL> /
  6.  
  7. 2 rows updated.
  8.  
  9. SQL> select * from t1;
  10.  
  11.          A          B
  12. ---------- ----------
  13.          1 .809607126
  14.          6 4.67696837
  15.  
  16. SQL> update t1 set b = dbms_random.value(a,a+2);
  17.  
  18. 2 rows updated.
  19.  
  20. SQL> select * from t1;
  21.  
  22.          A          B
  23. ---------- ----------
  24.          1 1.81326377
  25.          6 6.36075424
  26.  
  27. SQL> 
  28.  
PS: DBMS_RQANDOM.VA LUE(LOW VALUE, HIGH VALUE) RETURNS NUMBER
Jan 10 '08 #3
ericjb
6 New Member
check this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1* update t1 set b = dbms_random.value(a,a-2)
  5. SQL> /
  6.  
  7. 2 rows updated.
  8.  
  9. SQL> select * from t1;
  10.  
  11.          A          B
  12. ---------- ----------
  13.          1 .809607126
  14.          6 4.67696837
  15.  
  16. SQL> update t1 set b = dbms_random.value(a,a+2);
  17.  
  18. 2 rows updated.
  19.  
  20. SQL> select * from t1;
  21.  
  22.          A          B
  23. ---------- ----------
  24.          1 1.81326377
  25.          6 6.36075424
  26.  
  27. SQL> 
  28.  
PS: DBMS_RQANDOM.VA LUE(LOW VALUE, HIGH VALUE) RETURNS NUMBER
Thanks! That worked perfectly.
Jan 10 '08 #4
Dave44
153 New Member
check this:

Expand|Select|Wrap|Line Numbers
  1. SQL> ed
  2. Wrote file afiedt.buf
  3.  
  4.   1* update t1 set b = dbms_random.value(a,a-2)
  5. SQL> /
  6.  
  7. 2 rows updated.
  8.  
  9. SQL> select * from t1;
  10.  
  11.          A          B
  12. ---------- ----------
  13.          1 .809607126
  14.          6 4.67696837
  15.  
  16. SQL> update t1 set b = dbms_random.value(a,a+2);
  17.  
  18. 2 rows updated.
  19.  
  20. SQL> select * from t1;
  21.  
  22.          A          B
  23. ---------- ----------
  24.          1 1.81326377
  25.          6 6.36075424
  26.  
  27. SQL> 
  28.  
PS: DBMS_RQANDOM.VA LUE(LOW VALUE, HIGH VALUE) RETURNS NUMBER
alternatively he could use an approach like dbms_random.val ue(A - <boundary_numbe r>,A + <boundary_numbe r>) to get either + or - column A.
Jan 10 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
4173
by: Thomas Mlynarczyk | last post by:
I remember there is a programming language where you can initialize the random number generator, so that it can - if you want - give you the exactly same sequence of random numbers every time you initialize it with the same parameter. Can this be done with JavaScript? I couldn't find anything in the documentation. Basically, what I want to achieve is to obtain always the same sequence of random numbers for the same given initialization...
4
2695
by: Jack | last post by:
I have two files: sort_comparison.c++ my_sort.h sort_comparison.c++ calls this code in my_sort.h: void my_sort::fillArray(int arr,int n) { // const int random_number_range=1000000;
70
6233
by: Ben Pfaff | last post by:
One issue that comes up fairly often around here is the poor quality of the pseudo-random number generators supplied with many C implementations. As a result, we have to recommend things like using the high-order bits returned by rand() instead of the low-order bits, avoiding using rand() for anything that wants decently random numbers, not using rand() if you want more than approx. UINT_MAX total different sequences, and so on. So I...
5
3339
by: Peteroid | last post by:
I know how to use rand() to generate random POSITIVE-INTEGER numbers. But, I'd like to generate a random DOUBLE number in the range of 0.0 to 1.0 with resolution of a double (i.e., every possible double value in the range could come up with equal probability). I'd also like to be able to seed this generator (e.g., via the clock) so that the same sequence of random values don't come up every time. Anybody have an easy and fast...
15
597
by: felixnielsen | last post by:
This is something i have done before and i know its pretty simple, however i cant remember how it works exactly, and i need it i kinda hurry, so if someone would be so nice to drop a random number generator (actually i just need binary 1 or 0) i would be forever gratefull ;-)
104
5126
by: fieldfallow | last post by:
Hello all, Is there a function in the standard C library which returns a prime number which is also pseudo-random? Assuming there isn't, as it appears from the docs that I have, is there a better way than to fill an array of range 0... RAND_MAX with pre-computed primes and using the output of rand() to index into it to extract a random prime.
3
24523
by: JoelPJustice | last post by:
I am working through a VBA book by myself to help and try and improve my skills. However, the book does not give you solutions to certain problems. I have worked through this problem up until bullet point 3. Here is the code I came up with up until now. Function RandomNormal(Mean As Double, StdDev As Double) As Double Application.Volatile Randomize RandomNormal = (StdDev * Sqr(-2 * Log(Rnd)) * Cos(2 * 3.141596 * Rnd)) + Mean End...
13
2799
by: Peter Oliphant | last post by:
I would like to be able to create a random number generator that produces evenly distributed random numbers up to given number. For example, I would like to pick a random number less than 100000, or between 0 and 99999 (inclusive). Further, the I want the range to be a variable. Concretely, I would like to create the following method: unsigned long Random( unsigned long num )
3
2331
by: Manuel Ebert | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear list, who's got aesthetic advice for the following problem? I've got some joint probabilities of two distinct events Pr(X=x, Y=y), stored in a list of lists of floats, where every row represents a possible outcome of X and every float in a row a possible outcome of Y (which I will now call my matrix, altough I can't use numpy or numeric for
0
8278
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8807
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8701
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8466
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5615
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4290
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2701
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1588
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.