0
  1. A user first fills in some text fields, eg: name, email, phone.
  2. Then he is shown 15 items (1,2,3,... 15).
  3. Because we don't want number 1 be always in the beginning, we add some variance on the display order.
  4. The display order for this user (or for this session) will be reused later.
  5. Because of 4), we may either
    a) randomize the order once, then cache it, or
    b) calculate the order from some info of this user (or this session).
  6. For b), I am thinking to generate a hash from the text field inputs,
    then convert the hash to display order.
  7. The conversion does not need to be evenly distributed, that is,
    the probability of occurrence of each of the 15! (= 1.3e+12) permutations does not need to be equal.

M = number of items
P(1) = {1,2,3,...,M}
P(2) = {2,1,3,...,M}
P(m) = some permutation

h = hash( name, email, phone ), or hash( session id ), just a hash from some text
N(h) = an integer in the range [ 1, M ]

then the order we want = P(N(h))

Question: what is the good way to this conversion?

Ksthawma
  • 1,257
  • 1
  • 16
  • 28
  • 1
    why not use inputs to seed pseudo random number generator and then generate your permutation using the outputs from random calls? – TheGreatContini Aug 31 '17 at 20:16
  • Calculating the Nth permutation has been covered before, forexample: https://stackoverflow.com/q/7918806/555045 – harold Aug 31 '17 at 20:20

1 Answers1

1

As @TheGreatContini suggested, use your hash value to seed a random number generator and use it with Fisher–Yates shuffle to generate a random permutation.

algrid
  • 5,600
  • 3
  • 34
  • 37