Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document pseudoness of random numbers #3

Open
uliska opened this issue Feb 2, 2020 · 0 comments
Open

Document pseudoness of random numbers #3

uliska opened this issue Feb 2, 2020 · 0 comments
Assignees
Labels
new topic New feature or request

Comments

@uliska
Copy link
Owner

uliska commented Feb 2, 2020

From a private discussion:

Random numbers in Scheme are only random if you initialize them to some "outside" value, e.g. the current time. This has been discussed just a few days ago: https://lists.gnu.org/archive/html/lilypond-user/2020-01/msg00496.html
Probably I should do so in the example because otherwise there's no practical use for the function.

I read but it did not help. I tried using this (set! random-state (random-state-from-platform)) in a couple of places. I got 61 or nothing

Well, it seems David's explanation was less useful than I thought.
I don't know what random-state-from-platform is, and I get an error from this.

The full documentation is at https://www.gnu.org/software/guile/docs/docs-1.8/guile-ref/Random.html#Random, and there you can find the explanation and an example for seed->random-state which David referenced.
You need to call that procedure with "something that isn't the same every time", for example with

\version "2.19.82"

#(set! *random-state*	
       (seed->random-state 
        (cdr (gettimeofday))))

#(display (random 100))

While this isn't really documented (shame on Guile!) it seems seed->random-state expects a string but auto-converts numbers to that. So it is possible to use one of the parts of the current time pair to seed the random state and get a different number in every run.

I think this should be described somewhere. Maybe a section with "various topics"?

@uliska uliska added the new topic New feature or request label Feb 2, 2020
@uliska uliska self-assigned this Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new topic New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant