Donate Now Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

Results 1 to 1 of 1

Thread: The Limit of Randomize()

  1. #1
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Blog Entries
    29
    Rep Power
    142

    The Limit of Randomize()

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

    DTB

    [code=thinbasic]
    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.
    [/code]
    Attached Files Attached Files
    "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

Bookmarks

Posting Permissions

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