Random value within a range [message #38120] |
Thu, 21 March 2002 22:36 |
Stephen
Messages: 26 Registered: January 2000
|
Junior Member |
|
|
I am trying to create A RANDOM value within a range of 10.
I don't understand exactly how the DBMS_RANDOM.VALUE() works.
Please can anyone help.
I am going mad frustration.
Thank you
Steve
|
|
|
Re: Random value within a range [message #38136 is a reply to message #38120] |
Mon, 25 March 2002 00:26 |
Epe
Messages: 99 Registered: March 2002
|
Member |
|
|
Yow Steve,
I've never used it myself, but reading the Oracle Manuals I got a strong impression that it works the same way as it does in other languages (like C). Generating random values is rarely really random. The value is generated depending on a particular start value (here apparently called "the seed"). The generator will generate the same value over and over again if you use the same seed (so for each run you should use a different seed (to get different random values). To be sure to get a different seed in every loop, you can create a seed using a part of sysdate
i.e.: my_seed:=to_number(to_char(sysdate,'hhmiss'));
).
So I think it works this way :
1. initialise = give a starting value to the generator
dbms_initialize(123456);
(Oracle advises to use seeds larger than 5 digits)
2. generate the random value
my_random_variable := dbms_random.random;
3. to get a new starting value (to create a new random
value)
a) take a new seed
dbms_random.seed(654321);
(use a different starting value !!! If you use the
same value, you'll probably get the same value
again)
b) regenerate
my_random_variable := dbms_random.random;
4. after the last line where you use the random package
you seem to have to close it
dbms_random.terminate;
I hope it helped you...
Epe
|
|
|
|