mardi 14 mai 2019

Simple function to generate random number sequence without knowing previous number but know current index (no variable assignment)

Is there any (simple) random generation function that can work without variable assignment? Most functions I read look like this current = next(current). However currently I have a restriction (from SQLite) that I cannot use any variable at all.

Is there a way to generate a number sequence (for example, from 1 to max) with only n (current number index in the sequence) and seed?

Currently I am using this:

cast(((1103515245 * Seed * ROWID + 12345) % 2147483648) / 2147483648.0 * Max as int) + 1

with max being 47, ROWID being n. However for some seed, the repeat rate is too high (3 unique out of 47). In my need, repetition is ok but not too much.

Is there any better function that meets my need?




Aucun commentaire:

Enregistrer un commentaire