Quick question for those more computer-savvy than I am. Can you help me divide readers into five roughly equal groups (it’s for this week’s Casual Friday). In the past, I’ve relied on the “what month is your birthday in” question, but it won’t work when I need five groups.

Surely there’s a simple javascript out there that would automatically return a random number from 1 to 5. I’ve done a few searches, but most of the scripts I could find have been too complicated, requiring user input. I just want the number to be automatically generated according to my specifications.

If you know how to do this, please email me (remove dashes!), or just let me know in the comments.

And to show my cognitive psychology ignorance…
Notice how I read your question and focused very quickly on “He wants a javascript function.” While the others went straight to “How else can we solve the problem without using birth month?”.

This is actually an interesting question… how many ways can you fairly split a random population of people?

Some non-programming methods:

Use birth-month to split into six groups but then discard one group or tell one group to go away.

Ask them what state they live in, which can then be divided into 5 groups (this assumes your readership is randomly geographically distributed, which it may or may not be.)

Ask them the last number of their zip code, or phone number, or social security number, all of which should be randomly distributed, won’t reveal anything personal, and can be easily split into five groups.

Ask them to select the closest match they are to a list of five hair or eye colors.

Ask them to roll a five sided dice! (More relistically, a six-sided dice until a number one through five come up.)

Ask them to flip a coin five times and count the number of heads (this wouldn’t really work because it would require too much work and would be normally distributed around 2-3, but if you even need to fake a normally distributed population…)

Either ask them to input the minute-value from the current time (i.e. 6 from 4:26) The computer could do that but I’m assuming your technical solution doesn’t work.

(Simple:) Ask them to pick a number 1-5.

(More interestingly…) Show them a picture of you with your hand behind your back and saw “Guess how many fingers I am holding up?”

Cognitive Science question: Would there be any difference in bias between the last two methods? I think the first method would have a “favorite number bias” if that matters, but maybe pose the question differently and it wouldn’t? What about picking a letter, does that have a bias?

You offer some interesting suggestions, Joshua, but some of them don’t appear to meet the criteria of random assignment. First, you assume readership is wholly American, which is not the case. Questions based on geographical state, ZIP code, and SSN exclude non-Americans as written. Second, hair and eye color are not evenly distributed. I’m also not sure how close “pick a number between one and five” would come to being random and even. You point out this potential shortcoming yourself.

The dice idea and a modified coin idea could produce the desired result, but they require actual effort on the part of participants (not to mention props — perhaps I could roll a Boggle cube?). Many people would be eager to participate nonetheless, but I’m certain this complicating factor would diminish the pool of participants.

You did make one excellent suggestion that I never would have considered: time. Every potential participant has a computer. Computers display the time. I think your idea to ask participants to enter the last digit of the time would produce a tolerably even and certainly random distribution. If I’m ever faced with a similar dilemma, I will definitely be using your concept.

What’s really interesting about the time thing is that that’s actually the way most “random” number generators in computer science work. I think it’s highly likely (though I’m not positive on the specifics of javascript) that the Math.random() function Fletcher used draws its randomizer seed from the millisecond value of a computer’s time. Of course, Math.random() does a bunch of funky stuff to that value, but the time’s the ‘seed’ off of which the randomization is built.

Thanks for your critiques. I am aware that some of my suggestions were American-biased, like states, but as I mentioned in my intro sentence, I was approaching the question like a brain teaser so I threw out almost anything I could think of. Several of the biased ones could be adapted using a similar concept. Almost everyone responding to an online survey would have a phone number, even in other countries.

That is true that among certain populations hair color is not even (Asians have mostly black hair I believe.) It was just another idea.

And Jen, you are correct about Math.random() using time to seed the random algorithm. The reason the algorithm does other stuff instead of just using the time value itself (for thoes who don’t know) is that often programs will need a whole series of random numbers, and since they run so quickly it is highly likely the numbers generated (from the timestamp) will be the same or in order. It only works in this case because we just need a single value.

I am a computer programmer but wanted to think of non-computer ways to randomize a population.

I’d still like to see an experiment or study on randomness of “pick a number” methods.