Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Random Number... Thomas Kyte's solution or any other
here it is.
btw: http://www.dejanews.com/ is an excellent place to find archives of c.d.o.*
A copy of this was sent to Priya Pattada <priya_at_ssg1.com> (if that email address didn't require changing) On Tue, 03 Feb 1998 14:38:17 -0800, you wrote:
>Hi,
>
>How do I generate random numbers using Forms 4.5 & Oracle?
>
>I have a similar question as the one that was asked a couple of days
>back and but I can't find the reply to it.
>One posting said that Thomas Kyte had put a good Solution to it.
>
>If anybody has the solution, could you please email it to me.
>
>Thanks
>Priya Pattada
>
>Below is a copy of the previous posting.........
>
>Hi Sven,
>
>Thomas Kyte posted a pretty good solution to
>comp.databases.oracle.server or comp.databases.oracle.misc some two days
>
>ago.
>
>Sven Dummert wrote:
>>
>> Hello!
>>
>> I ask me, how i can generate a random number with Forms 5.0 and
Oracle??
>>
>> Any Idea?
>>
>> Please answer via email, because im not frequently reading this group!
>>
>> CU Sven
>
>
create or replace package random
is
pragma restrict_references( random, WNDS, RNPS );
procedure srand( new_seed in number );
function rand return number; pragma restrict_references( rand, WNDS ); procedure get_rand( r OUT number ); function rand_max( n IN number ) return number; pragma restrict_references( rand_max, WNDS); procedure get_rand_max( r OUT number, n IN number );
end random;
/
create or replace package body random
is
multiplier constant number := 22695477; increment constant number := 1; "2^32" constant number := 2 ** 32; "2^16" constant number := 2 ** 16; "0x7fff" constant number := 32767; Seed number := 1; -- procedure srand( new_seed in number ) is begin Seed := new_seed; end srand; -- function rand return number is begin seed := mod( multiplier * seed + increment, "2^32" ); return bitand( seed/"2^16", "0x7fff" ); end rand; -- procedure get_rand( r OUT number ) is begin r := rand; end get_rand; -- function rand_max( n IN number ) return number is begin return mod( rand, n ) + 1; end rand_max; -- procedure get_rand_max( r OUT number, n IN number ) is begin r := rand_max( n ); end get_rand_max;
-- begin select userenv( 'SESSIONID' ) into seed from dual; end random; / Thomas Kyte tkyte_at_us.oracle.com Oracle Government Bethesda MD http://govt.us.oracle.com/ -- downloadable utilities ---------------------------------------------------------------------------- Opinions are mine and do not necessarily reflect those of Oracle Corporation Anti-Anti Spam Msg: if you want an answer emailed to you, you have to make it easy to get email to you. Any bounced email will be treated the same way i treat SPAM-- I delete it.Received on Thu Feb 05 1998 - 00:00:00 CST
![]() |
![]() |