I need to generate a sequence of random (pseudorandom do suit) strings in such a way that the probability of two strings in the sequence being the same is negligible.
So, how to obtain a sequence of pseudorandoms?
Internet Computer Loading tells something sophisticated about entropy. But I don’t need entropy, because pseudorandomness is enough for my purpose.
Check out the UUID and ULID libraries:
GitHub - aviate-labs/ulid.mo: ULID Generator for Motoko
Perhaps they meet your requirements? I think they have a pseudorandom path.
It is unclear what
ULID.MonotonicEntropy does with entropy and how to run it to obtain a pseudo-random sequence.
May 17, 2023, 4:47am
We have a Prng library here:
motoko-lib/Prng.mo at main · research-ag/motoko-lib · GitHub
It provides SFC64 which is a known generator that is also part of numpy. The output is compatible with numpy.
It produces a sequence of Nat64 and you have to convert that to a string yourself. If it is a common use case then we could add that to the library (output as Text or Blob) for convenience.
May 21, 2023, 7:05am
We published the Prng library on Mops now:
It would be nice to add convenience functions to generate random values of other types than only Nat64. Hence the question what was the original requirement for the pseudo-random strings? Where they Blob or Text and what was the required character set?
Prng type is not usable for my purposes, because it is not a stable type.
Text in any character set.
May 21, 2023, 10:34am
You wish to persist the Prng’s internal state across updates? Or why does the generator itself have to be stable?
May 21, 2023, 10:36am
Does that mean you don’t care what the character set is or that you would like to be able to supply an arbitrary character set to the generator?
Yes. I want to persist Prng’s internal state across updates.
I want to store results of the generator in
Text DB keys in such a way that lexicographical order of keys matches order of the random numbers. The charset does not matter (except of, maybe, for debugging is better to use UTF-8 or even ASCII).