Oracle 10g introduced a number of functions that should be used in place of the RANDOM function. L_seed := TO_NUMBER(TO_CHAR(SYSDATE,'YYYYDDMMSS')) ĭBMS_OUTPUT.put_line('random= ' || DBMS_RANDOM.random) įrom Oracle 10g Release 1 onward, initialization and termination were no longer necessary as calls to DBMS_RANDOM automatically initialize the seed using the date. Added to that, it was necessary to initialize and terminate the random number generator.
In Oracle 9i the DBMS_RANDOM package was a little limited, having only the RANDOM procedure to produce random numbers. The NORMAL function returns random numbers in a normal distribution.ĭBMS_OUTPUT.put_line('normal= ' || DBMS_RANDOM.normal) The LEN parameter, not surprisingly, specifies the length of the string returned.ĭBMS_OUTPUT.put_line('string(''x'',10)= ' || DBMS_RANDOM.string('x',10)) Ĭombine the STRING and VALUE functions to get variable length strings.ĭBMS_OUTPUT.put_line('string(''L'',?)= ' || DBMS_RANDOM.string('L',TRUNC(DBMS_RANDOM.value(10,21)))) 'x', 'X' - uppercase alpha-numeric characters.The OPT parameter determines the type of string produced as follows: The STRING function returns a string of random characters of the specified length. For example, to produce random integer values between 1 and 10 truncate the output and add 1 to the upper boundary. Use TRUNC or ROUND to alter the precision as required. If the parameters are used, the resulting number will be greater than or equal to the low value and less than the high value, with the precision restricted by the size of the high value.ĭBMS_OUTPUT.put_line('value(1,100)= ' || DBMS_RANDOM.value(1,100)) When called without parameters it produce a number greater than or equal to 0 and less than 1, with 38 digit precision.ĭBMS_OUTPUT.put_line('value= ' || DBMS_RANDOM.value)
The VALUE function is used to produce random numbers with a specified range. L_seed := TO_CHAR(SYSTIMESTAMP,'YYYYDDMMHH24MISSFFFF') ĭBMS_OUTPUT.put_line('Run 1 : seed=' || l_seed) ĭBMS_OUTPUT.put_line('Run 2 : seed=' || l_seed) ĭBMS_ed (val => TO_CHAR(SYSTIMESTAMP,'YYYYDDMMHH24MISSFFFF')) If you want to be "more" random, then use a seed that is more unique, like a timestamp. In later releases it is seeded using the date, user ID, and process ID.ĭBMS_OUTPUT.put_line('i=' || i || ' : value=' || DBMS_RANDOM.value(low => 1, high => 10)) In Oracle 10g it is automatically seeded with the date. From 10g onward you don't need to explicitly call SEED.