You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defrandom(seed):
""" Returns a random number and the new seed value. Starlark is meant to be deterministic, so anything that made the language non-deterministic (such as random number generators) was removed. This is a Python implementation of a linear congruential generator I found here: http://www.cs.wm.edu/~va/software/park/park.html """modulus=2147483648multiplier=48271q=modulus/multiplierr=modulus%multipliert=multiplier* (seed%q) -r* (seed/q);
ift>0:
seed=telse:
seed=t+modulusreturnfloat(seed/modulus), seed
The text was updated successfully, but these errors were encountered:
I agree having a random module would be nice. Not everyone is building with pseudo-determinism as a hard constraint. That said we should include a few changes to make access to the random package opt-in by default. I think adding a random package merits exporting a second top-level loader (or at least a configurable top-level loader) that determines weather the random package is available.
The second thing I'd expect from such a package would be an explicit set of controls within the go runtime to wrap and control any seed values within the starlark runtime
What feature or capability would you like?
It would be nice to be able to generate random numbers.
Do you have a proposed solution?
Implement a
random
module that usesmath/rand
under the hood.Have you considered any alternative solutions or workarounds?
From @betterengineering:
The text was updated successfully, but these errors were encountered: