In Oracle Sql developer 11g, how do I generate a random integer and assign it to a variable? This is what I\'ve tried so far:
S_TB := SELECT dbms_random.value(1,
For a set of consecutive integers randomly distributed uniformly (in the example below between 1 and 10), I suggest:
select round(dbms_random.value(0.5,10.49999999999),0) from dual
Otherwise I'll unintentionally restrict the first and last number in the set to half the probability of being chosen as the rest of the set.
As pointed out by q3kep and GolezTrol, dbms_random.value(x, y) provides a uniform random distribution for values greater than or equal to x and less than y. So either of the following would be appropriate:
select trunc(dbms_random.value(1,11)) from dual
or
select round(dbms_random.value(0.5, 10.5), 0) from dual
As per documentation