Results 1 to 1 of 1

Thread: The Limit of Randomize()

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    The Limit of Randomize()

    Here are the results of my testing of the thinBasic function, Randomize().

    DTB

    Uses "CONSOLE"
     
    Global V1, V2 As Ext
    Global I As Quad
    
    
    Function TBMAIN()
    
    I = 1
    
    Do
    I -= 1
    Randomize(I)
    V1 = Rnd
    Randomize(I - 1)
    V2 = Rnd
    If V1 = V2 Then Exit Do
    Loop
    
    Console_WriteLine(I)
    
    
    I = -1
    
    Do
    I += 1
    Randomize(I)
    V1 = Rnd
    Randomize(I + 1)
    V2 = Rnd
    If V1 = V2 Then Exit Do
    Loop
    
    Console_WriteLine(I)
    
    WaitKey
    End Function
    
    '(The program assumes that for two seed values, I and J, that if the
    'the first value of Rnd for Randomize(I), equals the first value
    'of Rnd for Randomize(J), then the two pseudo-random sequences are
    'identical, and the seeds I and J are effectively the same.)
    
    'The output from the program is:
    
    '-16777216
    ' 16777216
    
    'Apparently, Randomize() has 16,777,216 possible different seeds.
    
    '(The negative seeds are correlated to the positive seeds.
    'For any number, I, the first value of Rnd in the sequence for
    'Randomize(-I), equals the first value of Rnd in the sequence for
    'Randomize(I), plus or minus 0.5. Whether plus or minus is used in
    'a particular case, is decided by requiring that both values be
    'in the interval, 0 < value < 1.)
    
    '16,777,216 equals 2^24.
    
    'So, I think, no matter how big the seed is, only 24 bits are used.
    
    'For seeds greater than 16,777,216, the sequences begin to repeat.
    'For instance, the sequence for 16,777,217 is the same as the sequence
    'for 16,777,216.
    
    'As the sizes of seeds continue to increase, the number of consecutive
    'seeds with the same sequence, increases. For instance, the sequences
    'for seeds, 1,677,721,665 - 1,677,721,791 are identical.
    
    'Therefore, I think that for seeds with more than 24 bits, the 24 high
    'significant bits are used.
    
    'Randomize() also works with floating point seeds. But, in that case, I
    'think that again, only 24 bits are used.
    
    'I forgot to mention that Randomize(0) seems to be a special case. The
    'first value in its sequence, is 0.
    
    Attached Files Attached Files
    Last edited by ErosOlmi; 04-03-2024 at 20:58.
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

Similar Threads

  1. RANDOMIZE[(Numeric_Expression)]
    By marcuslee in forum Core module
    Replies: 3
    Last Post: 10-09-2008, 18:56

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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