help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to create random characters?


From: Brad Collins
Subject: Re: How to create random characters?
Date: Fri, 19 Dec 2003 00:30:13 +0700
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3 (windows-nt)

Kai Grossjohann <kai@emptydomain.de> writes:

> My understanding is that you call (random t) once, eg after Emacs
> starts up or when your file is loaded.  After this, you can call
> (random 42) to obtain numbers in the desired range.
>
> Does it not work that way?  I think it's intended to work that way.
> If it doesn't, that might be a bug.

I don't think it's a bug...

,----[ Elisp Manual: Random Numbers ]
|    In Emacs, pseudo-random numbers are generated from a "seed" number.
| Starting from any given seed, the `random' function always generates
| the same sequence of numbers.  Emacs always starts with the same seed
| value, so the sequence of values of `random' is actually the same in
| each Emacs run!  For example, in one operating system, the first call
| to `(random)' after you start Emacs always returns -1457731, and the
| second one always returns -7692030.  This repeatability is helpful for
| debugging.
| 
|    If you want random numbers that don't always come out the same,
| execute `(random t)'.  This chooses a new seed based on the current
| time of day and on Emacs's process ID number.
`----

 When I evaluated (random t)

   I got 80264346

 But I need to get a single digit between 0-9 so I used (random 9)

 But this then uses the same seed every time so the sequence of
 numbers I'm returned will be repeated every time I restart Emacs.

 So I needed to limit the number of digits that were returned but at
 the same time make sure that it will always be random and not start
 giving me the same numbers I got the day before.

 I changed to the Clisp random* and things seem to work.

 Perhaps I've misunderstood this whole thing -- please correct me if
 I got this wrong... or why it's now working....  it wouldn't be the
 first time I got something to work the right way for the wrong
 reasons :)

b/

--
Brad Collins
Chenla Labs
Bangkok, Thailand





reply via email to

[Prev in Thread] Current Thread [Next in Thread]