Random seed tooling

I do not see dedicated support for generating random numbers in a smart contract. It would be possible to use concordium.get_slot_time as a random seed I guess. Have there been any other approaches or are there plans to support this in the future?

get_slot_time is definitely not random. Not for anything important. There is very little entropy in that so seeding a PRNG is not going to give you good results.

Generating proper randomness is a very difficult problem. There have been discussions in the past about having something, but no concrete solutions have been devised and we don’t have concrete plans in the near future to support randomness in smart contracts.

Ok, thanks for clearing this up. I am looking to generate random ids, nothing that would be cryptographically relevant.

Ok.

Just as long as you are aware that

  • slot time can be to some degree decided by the baker
  • once you’ve seeded your PRNG it is visible to everybody and thus predictable

and it does not matter for your use-case, it’s fine. :slight_smile:

Thanks for giving me some details.

Does that mean slot time can be different for contract execution on different bakers? That would make it unsuitable as seed because contract execution results would then differ between different bakers, or is that not what you meant?

Public visibility is not an issue for my use case, I am aware of that.

No, slot time will be the same between bakers once the transaction is in a block. Otherwise we would not have consensus.

1 Like