I can't seem to use DBMSRAND.
GRANT EXECUTE ON DBMS_RANDOM TO *schema*;
ORA-01031: insufficient priveleges
Not sure why as I'm using the DBadmin schema to grant, but does anyone have a work around for random number generation in oracle sql?
If you're really desperate you could roll your own, eg here's an LG one
SQL> create or replace
2 package global is
3 a number := to_number(to_char(systimestamp,'FF'));
4 end;
5 /
Package created.
SQL>
SQL> create or replace
2 function rand(r in number) return number is
3
4 mill constant number:=100000000;
5 ten_thou constant number:=10000;
6 lg_num constant number:=31415821;
7
8 v number;
9 w number;
10 x number;
11 y number;
12 z number;
13
14 begin
15 w:=trunc(global.a/ten_thou);
16 x:=mod(global.a,ten_thou);
17 y:=trunc(lg_num/ten_thou);
18 z:=mod(lg_num,ten_thou);
19 v := mod((mod(x*y+w*z,ten_thou)*ten_thou+x*z),mill);
20 global.a:=mod(v+1,mill);
21 return(trunc((trunc(global.a/ten_thou)*r)/ten_thou));
22 end;
23 /
Function created.
SQL>
SQL> select rand(100) from dual;
RAND(100)
----------
21
SQL> select rand(100) from dual;
RAND(100)
----------
72
SQL> select rand(100) from dual;
RAND(100)
----------
1
SQL> select rand(100) from dual;
RAND(100)
----------
43
but random number generation is a science so you should be aware of the all of the limitations and drawbacks of rolling your own.
https://en.wikipedia.org/wiki/Linear_congruential_generator
So your best bet is to get appropriate access to the appropriate packages.
sys as sysdbaorsystemusers, and then grant as in the question.to_char(SYSTIMESTAMP, 'FF')as SYSTIMESTAMP has resolution of nanoseconds (depending on your DB server). But for sure, the proper way of doing is: ask your DBA to getEXECUTEprivileges on DBMS_RANDOM.