jeudi 2 juin 2016

Generate random number, the same every time

I have collections of items (ActiveRecord_AssociationRelation).

I need to randomly pick one item from each collection, but it should pick the same item the second and third time etc.

I'm thinking of some kind of one way algorithm, like hashing. E.g. perhaps based on the length of the collection, let's say 50, it will always generate the number 34.

Any idea how I could accomplish this?




Aucun commentaire:

Enregistrer un commentaire