Re: 32-bit random numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Juergen,

This subject seems to be near the end,  for now  blink

Try please new function, it can give random 
integer atoms in full EU range with step=1.
Distribution is flat, as far as I can see.

include misc.e

type range(integer N)
    return N>=1 and N<=8388608
end type

constant K = 1073741823 -- the max EU integer
-- 1073741823 / 8388608 = 127.99999... -- i.e. N << K

global function rand_int_atom(range N)
       return K * (rand(N) - 1) + rand(K) - 1
end function
 
-- this function gives random integer atoms 
-- in [0.. up to 9007199246352383, by 1073741823] range 
-- with step = 1, flat distribution.


--- Testing -- flat or not flat

sequence RR

RR = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

atom a01,a02,a03,a04,a05,a06,a07,a08,a09,a10,
     a11,a12,a13,a14,a15,a16,a17,a18,a19,a20
     
 atom SS
      SS = 9007199246352383 / 20
     a01 = 01 * SS
     a02 = 02 * SS
     a03 = 03 * SS
     a04 = 04 * SS
     a05 = 05 * SS
     a06 = 06 * SS
     a07 = 07 * SS
     a08 = 08 * SS
     a09 = 09 * SS
     a10 = 10 * SS
     a11 = 11 * SS
     a12 = 12 * SS
     a13 = 13 * SS
     a14 = 14 * SS
     a15 = 15 * SS
     a16 = 16 * SS
     a17 = 17 * SS
     a18 = 18 * SS
     a19 = 19 * SS
     a20 = 20 * SS
     
atom NN  
     
NN = 100000

atom Z
for i=1 to NN do
 Z=rand_int_atom(8388608)  --<-- max range 1073741823 * 8388608 - 1
    if Z>=  0 and Z< a01 then
  RR[01] += 1
 elsif Z>=a01 and Z< a02 then
  RR[02] += 1
 elsif Z>=a02 and Z< a03 then
  RR[03] += 1
 elsif Z>=a03 and Z< a04 then
  RR[04] += 1
 elsif Z>=a04 and Z< a05 then
  RR[05] += 1
 elsif Z>=a05 and Z< a06 then
  RR[06] += 1
 elsif Z>=a06 and Z< a07 then
  RR[07] += 1
 elsif Z>=a07 and Z< a08 then
  RR[08] += 1
 elsif Z>=a08 and Z< a09 then
  RR[09] += 1
 elsif Z>=a09 and Z< a10 then
  RR[10] += 1
 elsif Z>=a10 and Z< a11 then
  RR[11] += 1
 elsif Z>=a11 and Z< a12 then
  RR[12] += 1
 elsif Z>=a12 and Z< a13 then
  RR[13] += 1
 elsif Z>=a13 and Z< a14 then
  RR[14] += 1
 elsif Z>=a14 and Z< a15 then
  RR[15] += 1
 elsif Z>=a15 and Z< a16 then
  RR[16] += 1
 elsif Z>=a16 and Z< a17 then
  RR[17] += 1
 elsif Z>=a17 and Z< a18 then
  RR[18] += 1
 elsif Z>=a18 and Z< a19 then
  RR[19] += 1
 elsif Z>=a19 and Z< a20 then
  RR[20] += 1
 end if
end for

pretty_print(1, RR / NN, {0,1,1,1})

--- flat, probabilities are almost the same
--- in all intervals.

while get_key()=-1 do end while
 clear_screen()
 
pretty_print(1, RR, {0,1,1,1})

--- or number of cases in each interval is almost
--- the same.


To get the top bound of EU integer atoms  for
this task, I used the following program:

atom k, t
integer K, z, y

K = 1073741823

k=0
z=0
t=0
y=0

while 1 do
 z += 1
 k += K
  if  
    k + 1 = k  then  exit  --  Rob suggested this probe
  end if
 t += K
 y += 1
end while

printf(1, "%d\n", {k}) -- the first bad bound
printf(1, "%d\n", {z}) -- the number of first bad iteration
printf(1, "%d\n", {t}) -- the last good bound
printf(1, "%d\n", {y}) -- the number of last good iteration
printf(1, "%d\n", {t/y}) -- control
printf(1, "%d\n", {1073741823}) -- control


Regards,
Igor Kachan
kinz at peterlink.ru

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu