Skip to main content

prig

function prig(
baseIndex,
shuffleID,
listSize): number;

Pseudorandom index generator implemented with Miller Shuffle Algorithm D variant NEW April 2023 aka: MillerShuffleAlgo_d

Miller Shuffle, produces a shuffled Index given a base Index, a shuffle ID value and the length of the list being indexed. For each inx: 0 to listSize-1, unique indexes are returned in a pseudo "random" order, utilizing minimum resources. As such this Miller Shuffle algorithm is the better choice for a playlist shuffle.

The 'shuffleID' is a 32bit value and be set by utilizing a PRNG. These bit determin the "random" shuffle. Each time you want another pseudo random index from a current shuffle (incrementing 'inx') you must be sure to pass in the "shuffleID" for that shuffle. Note that you can exceed the listSize with the input 'inx' value and get very good results, as the code effectively uses a secondary shuffle by way of using a 'working' modified value of the input shuffle ID.

Parameters

ParameterTypeDescription
baseIndexnumberThe index to be shuffled
shuffleIDnumberThe seed number
listSizenumberThe size of the list

Returns

number

shuffled index

See