Home » Other » Client Tools » Random value within a range
Random value within a range [message #38120] Thu, 21 March 2002 22:36 Go to next message
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 Go to previous messageGo to next message
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
Re: Random value within a range [message #38624 is a reply to message #38136] Wed, 01 May 2002 07:11 Go to previous message
Yong Kuk, Joo.
Messages: 1
Registered: May 2002
Junior Member
Use this

ex)
select dbms_random.value(184324.00, 190160.00) from dual;

in oracle8.1.7
Previous Topic: outer join help needed urgent..
Next Topic: REF CURSOR in SELECT Statement?- URGENT
Goto Forum:
  


Current Time: Thu Mar 28 18:10:25 CDT 2024