Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Will this produce a uniform distribution?

Love Hastings
#66666
Join date: 21 Aug 2007
Posts: 4,094
12-11-2008 14:21
((integer)("0x" + llGetSubString(llMD5String(inString,0), 0, 7))) % p, for p a prime.
_____________________
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
12-11-2008 15:43
In theory it should if your input set is large enough (i.e. if your input strings are only one character you'll probably only get about 128 results, and if p>128...). Keep in mind though that the modulo operator will produce a slight bias itself since 2^32 is not divisible by p (except for the trivial case where p=2). If p is large enough, this could become significant. For example, if p is somewhere around (2/3)2^32 then the first p/2 values are twice as likely as the last p/2 values. I've seen it recommended that you actually use division rather than modulo for pseudo-random number generation for this reason.
Love Hastings
#66666
Join date: 21 Aug 2007
Posts: 4,094
12-12-2008 08:48
Excellent! Thank you.
_____________________