1. #1
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default 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.

    cameyo
    Attached Files Attached Files

  2. #2
    Moderator User Gallery
    Join Date
    Jun 2004
    Location
    UK
    Posts
    7,679

    Default

    Hi cameyo,

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

    [VarSet,direction,RAND(10)]
    [If, (direction < 0) || (direction > 10), [Note,"Error"]]


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

    Marcus

  3. #3
    Senior Member User Gallery
    Join Date
    Jan 2003
    Location
    NYC
    Posts
    1,625

    Default

    Hi Cameyo,

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

    [VarSet,direction,IRAND(0)+5]
    and
    [VarSet,direction,IRAND(1)+5]
    and
    [VarSet,direction,IRAND(2)+5]

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

    Sven

  4. #4
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default Thanks

    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)
    Using RAND is my last chance

    cameyo

  5. #5

    Default

    Hi
    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)).
    -Pixolator

  6. #6
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default

    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):
    Image1.jpg
    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.... ... 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.

    cameyo
    Attached Files Attached Files
    Last edited by cameyo; 01-09-05 at 10:43 PM.

  7. #7
    New Member User Gallery
    Join Date
    Sep 2004
    Posts
    14

    Post

    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.
    Attached Files Attached Files

  8. #8
    Senior Member User Gallery
    Join Date
    Feb 2002
    Location
    France
    Posts
    14,110

    Smile Random number...

    At Start we have...
    N = something between 0 and 1 like 0.2561
    Pi = that the computer has in his memory Maybe 3.14159265358979 ....
    ^ = 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 ***
    N = [( N + Pi ) ^ 5 ] - Ent [( N + Pi ) ^ 5 ]
    Print N
    Goto

    Is not marvelous and simple ?
    You will obtain a regular uniform distribution randomizing
    0.814636029
    0.185563304
    0.723545765
    0.631390691
    0.582652538
    0.458977266
    0.140534350
    0.870127423
    0.089865958
    0.365182693
    ...
    At the end free to you to multiply by 10,100,... and take the entire part to obtain
    8
    1
    7
    6
    5
    4
    1
    8
    0
    3
    ...
    81
    18
    72
    63
    58
    45
    14
    87
    8
    36
    ...
    Pilou
    Is beautiful that please without concept! ( Me and maybe also E Kant)
    Pilou's Galerie Pilou's Tips Tuts Page
    Cameyo's ZPlace Art Surfing Albums
    Dedicaces Perpetual Challenges

  9. #9
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default how many random...

    Thanks all for reply.
    I had some problem with the internal math precision of Zscript
    I have written some more code to test the rand generator...
    Download the Zplace2 revI b4
    The first example show basic method:
    Start ZBRUSH
    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:
    Start ZBRUSH
    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:
    Brownian06_show.jpg

    Brownian07_show.jpg

    Thanks for try.

    cameyo

    p.s. sorry, i have some problems to upload images i'll try later...
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Brownian01.jpg 
Views:	56 
Size:	37.9 KB 
ID:	4704   Click image for larger version. 

Name:	Brownian05.jpg 
Views:	72 
Size:	61.3 KB 
ID:	4707  
    Attached Files Attached Files
    Last edited by cameyo; 01-09-05 at 08:38 AM.

  10. #10
    Senior Member User Gallery
    Join Date
    Dec 2003
    Location
    Chicago
    Posts
    5,537

    Default

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

  11. #11
    Senior Member User Gallery
    Join Date
    Feb 2002
    Location
    France
    Posts
    14,110

    Wink @Animuts

    If you take my pseudo above, no doubt that you will obtain a random landscape without artefact
    A random walk or a map by colors (in this last case no doubt that you obtain a foggy altitude image
    Pilou
    Is beautiful that please without concept! ( Me and maybe also E Kant)
    Pilou's Galerie Pilou's Tips Tuts Page
    Cameyo's ZPlace Art Surfing Albums
    Dedicaces Perpetual Challenges

  12. #12

  13. #13
    Senior Member User Gallery
    Join Date
    Jun 2003
    Location
    Germany
    Posts
    638

    Default

    nice patterns! looking forward to the rand solution!

    greets
    froyd
    nosce te ipsum!

    ZBrush Link Database: z-links.de
    chat with us on IRC: #zbrush / EFnet

  14. #14
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default More images...

    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
    Anyway, i think every pseudo-generator will generate a repetitive drawing...

    cameyo
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	Brownian03.jpg 
Views:	62 
Size:	121.2 KB 
ID:	4733  

  15. #15
    Senior Member User Gallery
    Join Date
    Apr 2001
    Location
    ITALY
    Posts
    1,270

    Default ...

    ...
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	RandomAlpha.jpg 
Views:	68 
Size:	171.3 KB 
ID:	4736  

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •