Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: rigorously predictable random numbers



On 5/2/2024 22:48, Ray Andrews wrote:


On 2024-05-02 20:09, Lawrence Velázquez wrote:
	The values of RANDOM form an intentionally-repeatable
	pseudo-random sequence; subshells that reference RANDOM
	will result in identical pseudo-random values unless the
	value of RANDOM is referenced or seeded in the parent shell
	in between subshell invocations.
Ok then at least this is intentional.  How does one obtain a genuinely random number then?  TBH, for my particular needs right now the standard behavior is perfect, but as a matter of principle I'd like to know how to get 'real' random numbers.  There will be a way.
'real' random numbers are not possible on a computer, but 'good enough' random numbers are available in /dev/random character device file.  I have also written the zsh/random module that uses system calls to access the same kernel 'random' pool, but it has yet to be accepted for addition to the next release.  It provides the SRANDOM parameter (32-bit unsigned) similar to modern bash, a zrand_float() math function for numbers between 0 and 1, and zrand_int(upper,lower,inclusive) to return an integer between two values (32-bit integer max)




Messages sorted by: Reverse Date, Date, Thread, Author