Skip to content
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

Deterministic Lightweight Pseudo-Random Number Generators #2019

Closed
igormcoelho opened this issue Oct 25, 2020 · 2 comments
Closed

Deterministic Lightweight Pseudo-Random Number Generators #2019

igormcoelho opened this issue Oct 25, 2020 · 2 comments
Labels
discussion Initial issue state - proposed but not yet accepted

Comments

@igormcoelho
Copy link
Contributor

igormcoelho commented Oct 25, 2020

Summary or problem description
I think Neo should provide interops for lightweight pseudo-random number generators, such as Mersenne Twister. These are cheap on gas costs, and quite useful, as fueling them with entropy-based hash seeds (from blocks, transactions, or mixed) are secure strategies for smart contract random solutions.
A follow up from nice discussion in #1657.

Do you have any solution you want to propose?
Introduce interops for Mersenne Twister and other lightweight pseudorandom generators.
Some Interop may, for instance, initialize the desired generator (Neo.Random.InitializeMT), and others may take pseudorandom values from given interval (Neo.Random.NextIntRange).

Note that, it's very important to provide Range-Based integer generation, such as NextIntRange operation), as mostly adopted practices using mod operator (GetRandom() % INTERVAL) are very biased (it is well known, but I can also look for academic works on that matter). One good example is the C++11 random generator library, that has the concept of "distributions", like uniform_distribution, to operate over generators in a less-biased manner.

[EDIT]:
In time, we should also DEFINITELY provide Neo.Random.Shuffle for arrays (and maybe... Neo.Random.Sort, why not? To keep things "symmetric" 👍 ).

Neo Version

  • Neo 2
  • Neo 3

Where in the software does this update applies to?

  • Interop
@igormcoelho igormcoelho added the discussion Initial issue state - proposed but not yet accepted label Oct 25, 2020
@EdgeDLT
Copy link

EdgeDLT commented Oct 26, 2020

Support! I have spoken to a few developers in the past who have asked about on-chain rng, specifically for games. I have pointed them to this in the past, but having interops for it sounds much better.

I hope we can provide something like this for those that don't want to go through oracles.

@igormcoelho
Copy link
Contributor Author

This post is actually amazing @EdgeDLT , I've crossed by it some months ago.. and in fact, generating pseudo-random numbers in a practical and less-biased manner has also been a challenge for "famous languages", such as C++. Only in C++11 standard, the uniform distribution pattern was introduced, and still today, I guess 99% of the developers just use the pattern "rand() % MAX" to extract range-based numbers.
Also, maybe few people are also confident with Mersenne Twister and others of the sort, but they are pretty good! As long as you seed them with a nice entropy, which is the "hard part", the rest should be easy for users. By providing them with such easy-to-use feature in a secure manner (which is), is the best possible world. Thanks for the support, let's see how it goes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Initial issue state - proposed but not yet accepted
Projects
None yet
Development

No branches or pull requests

3 participants