[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Random output in LilyPond Log
From: |
David Kastrup |
Subject: |
Re: Random output in LilyPond Log |
Date: |
Thu, 12 Jul 2018 22:15:35 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Karlin High <address@hidden> writes:
> On 7/12/2018 1:17 PM, Freeman Gilmore wrote:
>> I am using Frescobaldi and studying the Scheme Book. When I compile,
>>
>> mylist = #( list 'red random 12 )
>> #(display mylist)
>
> If this is an exercise to demonstrate random numbers, I wonder if it
> needs more parentheses.
>
> % CODE
> \version "2.19.80"
> mylist = #(list 'red (random 12))
> #(display mylist)
> % END CODE
>
> If I run it that way in Frescobaldi, it always returns: (red 3)
>
> If I use lilypond scheme-sandbox, I get things like this:
>
> guile> (list 'red (random 12))
> (red 3)
> guile> (list 'red (random 12))
> (red 4)
You could read the documentation for random.
Note that the initial value of ‘*random-state*’ is the same every
time Guile starts up. Therefore, if you don’t pass a STATE parameter to
the above procedures, and you don’t set ‘*random-state*’ to
‘(seed->random-state your-seed)’, where ‘your-seed’ is something that
_isn’t_ the same every time, you’ll get the same sequence of “random”
numbers on every run.
For example, unless the relevant source code has changed, ‘(map
random (cdr (iota 30)))’, if the first use of random numbers since Guile
started up, will always give:
(map random (cdr (iota 19)))
⇒
(0 1 1 2 2 2 1 2 6 7 10 0 5 3 12 5 5 12)
To seed the random state in a sensible way for non-security-critical
applications, do this during initialization of your program:
(set! *random-state* (random-state-from-platform))
--
David Kastrup