-
Notifications
You must be signed in to change notification settings - Fork 6
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
Not just [0,1), but also random int #22
Comments
Also duplicate of #21. |
Aye, will close. |
Yup, the current intention is that the seeded PRNG will support |
My original motivation is that "64 bits of random" is more fundamental to an RNG than "[0,1) double", but I guess that alone doesn't mean it has to be in the same spec. After all everyone knows that. The consideration around MAX_SAFE_INTEGER should maybe also get into your separate proposal. Or maybe we get a BigInt output, I still can't decide. |
In #19 (comment) I talked about how it might be useful to have a "correct dice roll" as a tangential. I still think that's important (people mess that up more commonly do you think), so I'm making a new issue.
Beyond just [0,1), I see potential use for a method for a random integer.
The
.randomInt()
methodTo obtain a random integer number from a PRNG object, the object has a
.randomInt()
method. On each invocation, it will output an appropriate pseudo-random number based on its seed, and then update its seed for the next invocation..randomInt()
is invoked with zero arguments, it returns a random unsigned 32-bit integer in the range [0, 2^32-1]..randomInt()
is invoked with one argument x, it returns a random integer in the range [0, h). x must be in the range [1,Number.MAX_SAFE_INTEGER
]..randomInt()
is invoked with two argument l, h, it returns a random integer in the range [l, h). h-l must be in the range [1,Number.MAX_SAFE_INTEGER
].Recommended implementation
See swiftlang/swift#39143.
Open questions
number
constrained to uint53 (MAX_SAFE_INTEGER), a 64-bit-or-whateverBigInt
, or anumber
constrained to uint32?The text was updated successfully, but these errors were encountered: