dimanche 30 mai 2021

Generating random number. How can I ensure no duplictes?

I'm writing an inventory application .For each entry, I need a random number generated as a ID for the transaction. Right now I have the following code:

Randomize 10
     newIDnum = Int(Rnd * 1000000)

I have a validation built in for if a duplicate gets added I get alerted, and from time to time I get such an alert.

I wanted to bring up the problem here to make sure I'm using this correctly for the intended outcome. I understand little about seeds and where the CPU gets the info to generate a random number (I understand its not truly random, but that's as far as I know). Simply I just need to make sure that no duplicate values are generated, or at least that I minimize the probability as low as possible.

Thank you!




Aucun commentaire:

Enregistrer un commentaire