-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
deprecate std/mersenne #18395
deprecate std/mersenne #18395
Conversation
what we need instead:allowing reusing std/random with a generic interface allowing to plugin |
I meant "Replace lots of useless code with a generic proc." |
you can the problem with Clearly, this API mirroring is not a good design. A good design would allow calling gauss, sample, etc generically on the random generator type |
I feel like a RNG concept would be nice here (ofc that'd have to wait for concepts to stabilize), similar to Rust's |
What's wrong with the default random number generator? I don't want interfaces everywhere, the parametrization either causes code bloat or indirect function calls... |
For one, the default RNG isn't cryptographically secure. Though I don't know why the |
Well we can consider that once we have a second RNG that anybody out there cares about. :-) |
So if apparently noone cares about |
mersenne is archaic and I don't know to which extend sysrand can implement a sane interface as there is some fallback to /dev/urandom (which is terrible). |
Hmm, perhaps we should just deprecate it then (and recommend |
I'm a physicist and care about it for example. If only, because in ROOT (CERN's HEP software framework) the class |
Make it a nimble package? An alternative to the stdlib random? Those who want it can use it, and those who don't are not bothered? |
Not sure if you're replying to me or not. But personally I don't care whether it lives in the stdlib or elsewhere. I care about the fact that the thing is implemented. |
Please make it a Nimble package. |
there's little point in RT parametrization on the RNG type so let's just discuss the CT parametrization via eg proc gauss(r: var Rand; mu = 0.0; sigma = 1.0): float
etc...
=>
type RngConcept* = concept
proc next(a: var Self): uint64
proc skipRandomNumbers(a: var Self) # could be optional
proc gauss(r: var RngConcept; mu = 0.0; sigma = 1.0): float
etc... really not much difference complexity wise.
it wouldn't cause code bloat in the generated binary any more than what the program calls, so if you only instantiate it with only std/random's default RNG, it wouldn't increase binary size. I'm not sure why it matters that it can fallback to /dev/urandom on some systems; such systems would anyway have that limitation if they wanted to implement The point is we can have gauss, sample, etc available generically to std/sysrandom, the default RNG in std/random, as well as 3rd party libs that conform to |
It means that the operation can fail. |
Should I remove or deprecate Mersenne, and create a new Github repo with Mersenne in it? |
/dev/urandom (unlike /dev/random) is non-blocking, and what should be used as fallback (and that's indeed what we do). https://www.2uo.de/myths-about-urandom Is the best resource I found on this topic, and a good read. If it fails (say with EINTR) we just retry, just like we do in io.readLine: # in readLine:
while true:
# fixes #9634; this pattern may need to be abstracted as a template if reused;
# likely other io procs need this for correctness.
fgetsSuccess = c_fgets(addr line[pos], sp.cint, f) != nil
if fgetsSuccess: break
if errno == EINTR:
errno = 0
c_clearerr(f)
continue
checkErr(f)
break Again, the main point is that someone who wants to implement gauss/sample/uniform from scratch on top of a CSPRNG like system randomness would have no benefit in doing so over simply reusing existing code from std/random generalized as mentioned earlier to be generic on |
It's irrelevant. You simply cannot read from |
meh, we can just add Which I've never heard of, seems like a hypothetical scenario. Again, this is a fallback, almost all systems (and all the OSes officially supported by nim) in use have APIs for that and don't need to /dev/urandom direcly (as can be seen in https://nim-lang.github.io/Nim/sysrand.html#urandom%2CNatural) |
Just because it's "character special" that doesn't mean that it produces random numbers... ;-) |
If a system is so compromised then hard linking One, probably slow source of true random numbers for seeding/crypto/other performance insensitive applications and one PRNG seem enough for the stdlib. The application areas are distinct enough that I don't think a "true Gaussian" adds much value. It is also unreasonable/out of scope for the stdlib to keep up with all the probability distributions that might get requested. So, I doubt we need layering/multisource RNs in the in-stdlib. There are already not one but three nimble packages with their own implementations of So, this PR could simply deprecate To help understand how much disturbance this might cause, I searched a clone of the nimbleverse I have. The only packages I could find that seem to depend upon
and two that actually use it:
There is who knows how much non-nimble "dark code" out there, of course..but only one real usage in 1500 packages suggests extremely weak reliance/low perturbation to deprecating now. |
Yes, that sounds good. I am added {. deprecated .} pragmas currently. |
I'd also add |
I'd only add. No need to deprecate individual procs, just the module |
Co-authored-by: konsumlamm <[email protected]>
Doc generation changes, I guess? Co-authored-by: konsumlamm <[email protected]>
You should maybe change the title of this PR to "deprecate mersenne" or similar and downvoters should perhaps reconsider their votes. :-) The whitespace changes seem a bit superfluous, but 🤷 also harmless. Other than that, it's looking fine. |
Co-authored-by: Timothee Cour <[email protected]>
Needs a changelog entry. |
This reverts commit ea1961e.
Co-authored-by: konsumlamm <[email protected]> Co-authored-by: Timothee Cour <[email protected]> Co-authored-by: Andreas Rumpf <[email protected]>
I added a couple of functions to the Mersenne Twister module. I am sure that very few people use the module, so I picked it to be safe, as I am an incompetent algorithm writer.