If I require a pseudo-random number (PRN) in the internal working of a function in liquidity, is there a way to do it? Is there one in Michelson? I already know about the way to send a PRN through RPC call, but I'm looking for something that can be applied inside a function.

  • 1
    Of course you can do it. You can for example directly implement some simple PRNG in Michelson/Liquidity, or use the hash instructions (BLAKE2B/Crypto.blake2b etc). But you probably shouldn't... Why do you want pseudorandomness?
    – Tom
    Feb 7, 2019 at 7:20
  • I am not planning to use it for security purposes so probably I will create my own "somewhat-PRNG". My main need was to sample unique strings from a random sample space to serve as ID values and I was looking for a possible solution for that. Is there another way to generate UIDs that are 'random looking'?
    – pathfinder
    Feb 7, 2019 at 8:52
  • 1
    Can you explain why you need these IDs and what you are trying to do with them? There likely is a better way.
    – Arthur B
    Feb 7, 2019 at 9:26

1 Answer 1


If what you mean is a non-predictable source of randomness, no, there is none. Any information that could be used for that could either be predictable by a user, or tempered by a malicious baker.

You should probably use an external source of randomness, as the oracle presented in here.

An improvement of that would be to use commitments, i.e. the oracle would push a hash in the contract before the game, and send the random number (and a nonce) after the game, the contract checking that the hash and the random number match (with the nonce). Commitments prevent oracles from changing the random number during the game...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.