How random is "random"?

Discussion in 'Rebol' started by swhite, Jan 25, 2011.

  1. swhite

    swhite Member

    I have a script that, when it runs, displays the contents of a text file. The text file is randomly selected from all the text files in a particular directory. The method of selecting the file is to assemble a list of all the file names, generate a random number between 1 and the length of the list, and pick that file. In code, it would be something like:

    FILE-LIST: read %.
    FILE-NUMBER: random length? FILE-LIST
    reduce load/all pick FILE-LIST FILE-NUMBER

    Does anyone know if the "random" function will return a really random number every time I run the script, or will it always start at the same number with each fresh execution of the script (a pseudo-random number, I believe, is the term).

    Thank you.
  2. swhite

    swhite Member

    I might have answered my own question by rereading the documentation, which I did not completely and correctly understand the first time. It appears that there should be a line of code like this:

    random/seed now

    somewhere in the program BEFORE the line that generates my random number. The above line causes the "random" function NOT to start the same way all the time.

    Thank you.

Share This Page