Random selection

Hello everyone!

Here I am again. I completed the first part of my Daml code for my PhD, now I have to do the second part. In the meantime, I also took a Haskell course to better understand Daml and try to bother you all as little as possible. :smiley: :smiley:.

I would like to have some guidance and initial suggestions on how to approach this second part. Here is what I have to do. in my hypothetical scenario, I have a network with entities who can access the ledger, and I have to invite some of them to check some documents. Here are the key points:

  1. Make a list of the entities part of the network.
  2. Create a group through a random selection (the group is composed of a maximum of 5 minimum 1))
  3. Send them an invite to assess the documents

Could someone point me in the right direction to start my project? As usual, I would really really appreciate your help!!! :pray: :pray: :pray: :pray: :pray:

@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