Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dbms_random 2

Status
Not open for further replies.

fosa

IS-IT--Management
Mar 18, 2008
26
0
0
FR
Hi all,


How can I get radom value
from dbms_random where I can get the upper limit

say I have 0 to 1 as possible values

0,
....
0.00000000000001
.....
0.00000000000002
...
0.99999999999999
...
1

how can I obtain values from 0 to 1 randomly ?

0 <= values <=1

 
How about:
Code:
select dbms_random.value(0,1) from dual;

DBMS_RANDOM.VALUE(0,1)
----------------------
            .742841368
SQL> /

DBMS_RANDOM.VALUE(0,1)
----------------------
            .899262571
SQL> /

DBMS_RANDOM.VALUE(0,1)
----------------------
            .821433095
Let us know.

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
yes but Iwant to have 1 into
the result
dbms.random give only value under 1

 
What do you mean exactly ? Do you mean you want to have 1 come up as part of the (infinite) range of possibilities of decimal numbers that exist between 0 and 1 ? I imagine both 0 and 1 are possible return values, but you are extremely unlikely to see either of them because there are so many alternatives.

Or do you mean you want a random number that should be either 0 or 1 ? If the latter, select a range between 1 and 10 for the random number and truncate it to convert it to an integer. Then apply MOD(,2) so that you only get either 0 or 1 e.g.

select mod(trunc((dbms_random.value(1,10))),2) from dual

 
I think you would probably have to pick the number of decimal places you need in your result and then use the round function. For example

Code:
select round(dbms_random.value(0,1),2) from dual

returned a "1" for me after 91 executions.
 
OK thanks every body

I think

select round(dbms_random.value(0,1),2) from dual

is interesting

I wanted to have 1 among the infinited solution
of radom generated vaue between 0 and 1


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top