[thelist] Consistant shuffle per user

Lee Kowalkowski lee.kowalkowski at googlemail.com
Wed May 9 04:09:22 CDT 2012


On 8 May 2012 16:47, erik mattheis <gozz at gozz.com> wrote:
> I wish to shuffle the order of sibling elements but retain the
> shuffled order each time the page is loaded. Can someone give an
> example of a pseudo-random ordering mechanism based on a seed? What
> would be best to use as a seed? A cookie? IP address? User agent
> string?

My JavaScript pseudo-random function is pretty much this:

	var seed = ???;

	this.pseudoRandom = function()
	{
		seed = (seed * 134775813 + 1) % 0x100000000;
		return seed / 0x100000000;
	}

The seed has to be numeric, but a cookie or IP address based seed can
work adequately for per-user purposes, depending on requirements.  I
wouldn't have thought the user agent string would be ideal based on
your message subject.

-- 
Lee
www.webdeavour.co.uk


More information about the thelist mailing list