Goto main content

random

Random number generator.

RANDOM

NAME

random - Random number generator.

SYNOPSIS

random([min:integer, max:integer, seed:integer, init:bool);

DESCRIPTION

This function generates a random number. This number will be contained between the set minimum (by default it is 0) and the set maximum (by default it is RAND_MAX). If "init" is true, the sequence is initialized by a seed (by default, the current is in microseconds).

For a same seed, the sequence is always the same.

Then function RAND_MAX() returns the maximum random number as a double.

EXAMPLES

res={{random(seed:1,init:true)/RAND_MAX(); }}. return res=.840188.
res={{
                random(min:4,max:17,init:true,seed:1);
                " " ;random(min:4,max:7);
                " " ;random(min:4,max:7);
                " " ;random(min:4,max:7);
}}. return res=15 5 7 7.
res={{random(min:1,max:6,seed:1,init:true); }}. return res=6.
res={{
                random(min:1,max:6,seed:1,init:true);
                b=0; n=0;
                for(i=0;i<20;++i)  do
                        " ";a=random(min:1,max:6); a; b+=a; n++;
                endfor
                ", b=";b;
                ", n=";n;
                ", avg="; b / n;
}}. return res=6 3 5 5 6 2 3 5 2 4 3 4 3 4 6 6 4 5 1 4 1, b=76, n=20, avg=3.

for(i=0;i<80;++i)  do
        a=random(min:0x21,max:0x7a); chr(a);
endfor

might return

@'naXq"D*2LR[sqD2lE</[Y2p@4GkTh1[[q8Rr[[*-3e&).7uRR)31:)PNP@(=QbxGzO?[0HgB3lK@(F
rZN+kh3@;b`B%6)"])Q!c`IO([AS!Hxs(K#r858Swwt!2##n+Som9>B@xbry0oq8@s/X.F0+C*,T-.H8
a<+yYL>W46UC+L[JDi(R58\WAg1NuXe[toYSAw0T2dw<5WfYFn1[+l7LYHyS&c3zXkRxhaRyKN;`+'?P
uO0%AGQyoORt8dtpULmB3EA]r\C#baR\6baV.7U"f-v$posK@fmR145(oX+W>\9TCz0Q7eS#qN&gCy7c
e*;u>O#3,-iJi($2'3b=w:?mhEY1Cps.z4)>c+Pn8>>&EB7LUyhQ9-D'Q#7ts0'sC06+:eyR)=XM^ox8
mfi,r32H6HB.WI'zX<*r'(I/D&\(uZ@hE.s=A*eVQ,d.Tj-2,6)2>QAbW"jR\/?&<7C]@-8q9!%mk2$v
H,.e]NM:P<k1J/7fFYHff_]$`aqPrtL@&Y*c-W"]rmmB")-GbU3N:oRyVHONBzmHYw0eS2GK%:l&CyM+
S_XlT/k/W?\x>NEwJUa#f.MkH>pj<Cto(Q`\`Pj<nL:2z^.J9oL%#xoJ<e9W.3K5d1pIa`eT2$f1bsZz
h+$j)r9D]R!jdK%M\uuBZ_vkcb"J[[IHfM7nDP7''7pkbt>Cn9eNxa?`H@/(!WOf*fYM<oTC,I3mCP66
hzde`(J-HY4H6c3?Nlli`E1lnD^6tsKas5LY<vecTy1jbC.65z$uD5f7YILRBw9:2erM`]6:\G*Cj8X$

SEE ALSO

{{ include("includes/maths.sn") }}

AUTHOR

Written by Pierre Laplante and Caroline Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

 

Edit

© 2021 extenso Inc. All rights reserved.