Random selection

@claudia_giannoni
I trust you’ve already got the answer to this question, as I see you made a similar post on Stackoverflow, on which you received a response. Therefore my reply here is mainly for housekeeping and posterity reasons.
If I understand correctly, the challenge you’re facing is with doing a random selection, and that is because Daml does not provide a random number generator. The reason why there’s no random number generator in Daml is because computations in Daml need to be deterministic and always produce the same result given the same input values. So, the only way you can create the groups that you require is by determining the composition of these groups off-ledger. In other words you’d need to create a ledger client application, where you can use a random number generator and compose the groups you need through random selection of members from the network. And then, if you wish to store these groups on the ledger, you can submit commands to create Daml contracts storing the groups with pre-determined members.
Here are the links to a couple of previous discussion on the topic of using random number generator in Daml.
Generate random integers
UUID missing in DAML
And here’s the link to the thread on Stackoverflow.
Random selection Daml

1 Like