IRAND problem

Hi all,
i have a problem with the IRAND function…
The following zscript executes IRAND(9) <iterations> times.
For each iteration the script add “1” to the relative vector MoveList(Random Value).
In this way MoveList(i) contains, at the end, how many times the value “i” was been selected (for i=0 to 9).
With 5000 iteration i suppose to see each MoveList(i) with a value of 500 (+/-)…
…but i have the following result:
Number of “0” extracted: 277 (*** strange value )
Number of “1” extracted: 553
Number of “2” extracted: 553
Number of “3” extracted: 561
Number of “4” extracted: 555
Number of “5” extracted: 552
Number of “6” extracted: 566
Number of “7” extracted: 539
Number of “8” extracted: 577
Number of “9” extracted: 267 (
strange value ***)
I have tried again and again, but with the same result (i got different values, but with the same trend to have the first and the last value very strange)
Clearly, the IRAND is NOT uniform !!! (or i have made some mistakes :))
I hope the script will clarify the situation.

The question
Is there some mistakes in my script or IRAND is not uniform ?

Thanks for viewing…and for helping.


Hi cameyo,

I know nothing about Math functions :slight_smile: but RAND seems to work ok:

[If, (direction < 0) || (direction > 10), [Note,“Error”]]

(I changed your code a little…) so perhaps something wrong with IRAND?


Hi Cameyo,

As a test, substitute the following lines and run the script:



IRAND does an integer rounding operation and I think the distributions are as you’d expect, aren’t they?


Thanks Marcus and Svengali.
I suspect the first and the last number of IRAND range don’t have…the 0.5 of previous (or next) number (as Svengali point out).
I have tried your hint, but i don’t think the distribution is uniform.
I have write a graphic routine to trace out the error (the “drunk” walking), and the mistery is not solve …(maybe Aurick or Pixolator) :slight_smile:
Using RAND is my last chance :wink:


cameyo: Yes, it is the start/end .5 which are responsible for the uneven IRAND distribution that you are getting. When using IRAND(9) you get 9 equally distributed results, not 10 (the first .5 and last .5 are of the same circular range).
You should be able to achieve a uniform distribution of 0-9 by using INT(RAND(10)).

Thanks Pixolator.
I have tried your hint (INT(RAND(x)), with the following result (1000 iterations):
Number of “0” extracted: 1022
Number of “1” extracted: 986
Number of “2” extracted: 1059
Number of “3” extracted: 950
Number of “4” extracted: 984
Number of “5” extracted: 1012
Number of “6” extracted: 1041
Number of “7” extracted: 1025
Number of “8” extracted: 971
Number of “9” extracted: 950
All works fine, but…
Now i have write a small “Walking Drunk” routine with the following result (50.000 iterations):
The routine starts drawing an object in the center of the canvas and move (one step) random in one of eight direction (N, NE, E, SE, S, SW, W, NW), then move random for the number of iterations.
The image shown a regular pattern… :o… not a random pattern.
The word of pseudo, random, aleatory number is very misterious…Tonight (i hope) i’ll write a personal random number generator and i’ll post the script to do some tests.
Now you can try with the Zplace2 revI beta2 version: set the parameteres and press the “W” button…

Thanks for trying.


It is possible to use the Congruent Pseudo-Random Number Generator (PRNG) x(i+1) = k*x(i) mod p.
For example good results give p= 5087, k=2900. But it is better to find big p & k that the big period of not repeating sequences of numbers was.
Look an example for numbers 5087 and 2900 in a script WALK2-RVy.txt.


WALK2-RVy.txt (2.65 KB)

At Start we have…
N = something between 0 and 1 :large_orange_diamond: like 0.2561
Pi = that the computer has in his memory :large_orange_diamond: Maybe 3.14159265358979 … :wink:
^ = Power of a number : Example 3 ^ 5 = 3 * 3 * 3 * 3 * 3 = 243
Ent = the Entire part of a decimal number : 3 is the entire part of 3.14

*** Pseudo code ***
:red_circle: N = [( N + Pi ) ^ 5 ] - Ent [( N + Pi ) ^ 5 ]
Print N
Goto :red_circle:

Is not marvelous and simple ? :smiley:
You will obtain a regular uniform distribution randomizing :sunglasses:

At the end free to you to multiply by 10,100,… and take the entire part to obtain



Thanks all for reply.
I had some problem with the internal math precision of Zscript:evil:
I have written some more code to test the rand generator…
Download the Zplace2 revI b4
The first example show basic method:
Load Zplace2
Select Sphere 3D
Set DrawSize to 5
Press the “Snap” switch
Open the “Walk” section
Press Ctrl-D (place Sphere3D on canvas center)
Now select this color R= G= B=
Set iterations to 10 (10.000 iterations)
Press “Randomize” button (To start with new seed)
Press “ShowInfo” switch
Now press “Drunk Walking” button (or press Ctrl-W)
You can see the sphere3D random movements on canvas…
You can stop the walking pressing ‘ESC’, you can restart walking pressing ‘Ctrl-W’.
In the second example we start another walking, but with a new property: each time the color of object changes to reflect how many times that place was reached:
Load Zplace2
Select Sphere 3D
Set DrawSize to 5
Press the “Snap” switch
Open the “Walk” section
Press Ctrl-D (place Sphere3D on canvas center)
Now select this color R=255 G=255 B=255 (white)
Set iterations to 10 (10.000 iterations)
Set sColorR = sColorG = sColorB = -10 (grayscale). You can see the selected colors in the palette.
Press “Randomize” button (To start with new seed)
Press “ShowInfo” switch
Now press “Drunk Walking” button (or press Ctrl-W)
You can see the sphere3D random movements on canvas…with different color where is located multiple placements.
Some hints:
Try with different objects (3D, 2D 2.5D tools), different _MoveX and _MoveY values, different color ramp, etc
You can overlay two or more “walking” with different Z…then render with shadow
To obtain a ‘regular walking’ you must have _MoveX = _MoveY = DrawSize/2
If sColorR = sColorG = sColorB = 0 the ‘walking’ is monochromatic.
You can stop the ‘walking’ by pressing 'ESC, press ‘w’ to show the GYRO, move the object and restart ‘walking’ with ‘Ctrl-W’.
Use a 4096x4096 canvas with Drawsize=8 and _MoveX = _MoveY = 4 for best result.
With high mumber of iterations the procedure will draw strange regular pattern…

Here is some examples:

Thanks for try.


p.s. sorry, i have some problems to upload images:confused: i’ll try later…





cool you just gave me an idea for creating a random landscape…now I will have to test it in revI. :smiley:

If you take my pseudo above, no doubt that you will obtain a random landscape without artefact :slight_smile:
A random walk or a map by colors (in this last case no doubt that you obtain a foggy altitude image :rolleyes:

:smiley: Frenchy!!

nice patterns! looking forward to the rand solution! :wink:


Hi all,
thanks for reply…
Frenchy: i’ll try your random generator tomorrow. Thanks.
RVy: thanks for your PRNG. I’ll try it too. I have read your zOthello script…very interesting.
The script will allow to select the random generator. I have written a random generator, but the range of floating number is so small :cry:
Anyway, i think every pseudo-generator will generate a repetitive drawing…








Damned! You obliged me to re-prog :smiley:
Test with a sympatico free Prog :+1: (For Windows and Unix and Linux and PS2:grimacing: )
(only default for the moment : He has no color(just Black & white in Drawing mode) :frowning:
In text mode yes some colors :wink:
yaBasic :sunglasses: (Yet An Another Basic) :laughing:
If you use it, Install it, use your favorite Editor, and make careful at that :warning: a “A” is different of a “a” :warning: He he :roll_eyes:
Just drawing a line with Startline and Endline with Pilou randomizing
Something like that :slight_smile: (it’s not pseudo code this time, it’s real code :slight_smile:

open window 1040,778 …// open a graphic window
N = 0.2561 …// initialize N to a number <0
for T=1 to 2000…// draw 2000 lines
N = (( N + pi ) ^ 5 ) - int(( N + pi ) ^ 5 ) …// the Pilou randomize system (thx Jp-Petit)
X = int(N1040) …// Xposition of the Startline
N = (( N + pi ) ^ 5 ) - int(( N + pi ) ^ 5 )
Y = int(N
778) …// Yposition of the Startline
N = (( N + pi ) ^ 5 ) - int(( N + pi ) ^ 5 )
X1 = int(N1040) …// Xposition of the Endline
N = (( N + pi ) ^ 5 ) - int(( N + pi ) ^ 5 )
Y1 = int(N
778) …// Yposition of the Endline
line X,Y,X1,Y1 …// draw a line
next T

Seems uniform and regular :wink:
ps You can make a “Stand Alone” like this One (the above prog) (for Windows : an “.exe”)
Pss Compiling is also possible!
And an Editor exist YabEdit

keyboard broke? good to see from you again,more info to come?

Hi all,
Frenchy: the problem is not with your random generator, but with the internal math of zscript…in fact the range of floating number is very small.
I have developed a new version of ‘drunk walking’ with some new images.
I will post it tomorrow…now i have a slow internet connection :cry:

Gary Komar: how are your beatiful virtual girl ?


…Cameyo , Frenchy, Gary ,you have all my admiration …

it’s happened everytime i don’t understand somethingh (often:D ).
For me what are you talking about is like Greek or chinese…