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!
4 2839
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.
check this: -
SQL> ed
-
Wrote file afiedt.buf
-
-
1* update t1 set b = dbms_random.value(a,a-2)
-
SQL> /
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 .809607126
-
6 4.67696837
-
-
SQL> update t1 set b = dbms_random.value(a,a+2);
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 1.81326377
-
6 6.36075424
-
-
SQL>
-
PS: DBMS_RQANDOM.VA LUE(LOW VALUE, HIGH VALUE) RETURNS NUMBER
check this: -
SQL> ed
-
Wrote file afiedt.buf
-
-
1* update t1 set b = dbms_random.value(a,a-2)
-
SQL> /
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 .809607126
-
6 4.67696837
-
-
SQL> update t1 set b = dbms_random.value(a,a+2);
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 1.81326377
-
6 6.36075424
-
-
SQL>
-
PS: DBMS_RQANDOM.VA LUE(LOW VALUE, HIGH VALUE) RETURNS NUMBER
Thanks! That worked perfectly.
check this: -
SQL> ed
-
Wrote file afiedt.buf
-
-
1* update t1 set b = dbms_random.value(a,a-2)
-
SQL> /
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 .809607126
-
6 4.67696837
-
-
SQL> update t1 set b = dbms_random.value(a,a+2);
-
-
2 rows updated.
-
-
SQL> select * from t1;
-
-
A B
-
---------- ----------
-
1 1.81326377
-
6 6.36075424
-
-
SQL>
-
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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;
|
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...
|
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...
|
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 ;-)
| |
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.
|
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...
|
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 )
|
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
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |