[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Change of random seed
From: |
Shawn Wagner |
Subject: |
Re: Change of random seed |
Date: |
Fri, 5 Aug 2022 23:45:18 -0700 |
Heh. Another half-finished project I had was porting random number code from another project that uses a bunch of OS specific ways to get a strong random seed - getentropy() on Linux and OpenBSD, arc4random on other BSDs (Actually using that for all random number generation if available), some Windows API, /dev/urandom, etc.... Looks like the gnulib getrandom does pretty much the same thing, so I can scrap that work.
Hey all,
Just a heads up that I've slightly refactored the init_random function into a separate source file and changed the seed to use getrandom(2).
Looking over the getrandom source in gnulib, I believe this should be compatible with platforms other than GNU/Linux. However, if it gives you a problem, please let me know.
Although a small change, this foreshadows a larger body of work which people may find interesting. I intend to implement a `rand` program capable of simulating random numbers drawn from popular probability distributions.
This is intended to be analagous to functions like runif, rnorm and rexp in the R programming language. In future, you will be able to do things like `rand norm --mean=3 --stdev=1.2 10` or `rand exp --rate=5 1` from your shell, where the R equivalents would be `rnorm(10, 3, 1.2)` and `rexp(1,5)`.
So, the first step is to set up the skeleton with a couple of extra source files, and switch to a more standard way of seeding random numbers :)
~ Tim