Reputation: 3216
I need to generate a random value that can be 0 or 1. I tried this: select floor(DBMS_RANDOM.VALUE (0, 1)) from dual
but there is a very very very low possibility of get value 1. Is there any chance to get this where the possibilities for 0 and 1 are similar?
Upvotes: 3
Views: 5128
Reputation: 8376
DBMS_RANDOM.VALUE(0,1)
will never return 1. From the documentation:
low The lowest number in a range from which to generate a random number. The number generated may be equal to low.
high The highest number below which to generate a random number. The number generated will be less than high.
You want: floor(DBMS_RANDOM.VALUE(0,2))
Upvotes: 4
Reputation: 172458
Try to use round
instead of floor
:
select round(DBMS_RANDOM.VALUE (0, 1)) from dual
Upvotes: 6
Reputation: 7403
Use DBMS_RANDOM.RANDOM to get an integer, and mod (n,2)
to get 0 (even number) or 1 (odd number)
Upvotes: 3