Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

My Aim:

I'd like to a have a function that takes an email address and outputs a quasi-random number of 1, 2, 3, or 4.

A little detail:

By quasi-random number I mean that given a typical population of email addresses, the probabilities of getting a value of 1, 2, 3, or 4 are roughly equal, and that obvious systematic properties of the email address such as the domain name do not affect the probability of getting a value of 1, 2, 3, or 4.

A little background:

I have an online experiment written in inquisit where participants log in on two occasions. I want to randomly assign participants to one of four groups. While this is easy to do for one session (I can just use a random number generator), I need some way of remembering the allocation across sessions. Thus, I thought that I could extract a quasi-random group allocation from the participant email. I'm also limited in the set of functions that I have at my disposal (see here for full list). The string functions are: tolower toupper capitalize concat search replaceall contains startswith endswith substring trim trimright trimleft length format evaluate

Initial Thoughts:

I thought about trying to extract a set of features of the email address that returned a value of 1, 2, 3, or 4 with roughly equal probabilities. Then, I could sum these properties and get the mod 4 plus 1 of that. Thus, assuming something like the central limit theorem, I might get close.

Possible features that came to my mind:

  • length of string
  • position of first "a", "b", etc.
share|improve this question
A very interesting problem. Do you have a sample of "typical population of email addresses" at hand ? Additionally it is not guaranteed, that the email-addresses of the visitors do have the same another/different structure, but since you are only looking for an approximation.... Second question: Are you able to set the seed of the RNG ? – steffen Feb 16 '11 at 9:26
5  
Sounds like you want a 'hash function': en.wikipedia.org/wiki/Hash_function This is in the realms of computer science rather than statistics though, so I'm not sure it belongs on CrossValidated. – onestop Feb 16 '11 at 10:20
1  
hmpf ;) ... I intended to write the same. @Jeromy: Especially this part of the site (en.wikipedia.org/wiki/…) could be interesting for you. – steffen Feb 16 '11 at 10:51
@onestop Thanks for the tip about hashtags. With regards to whether the question is on topic for the site, I think random allocation of participants to groups is inherently related to study design, which in turn is related to inferences from data. – Jeromy Anglim Feb 16 '11 at 14:20
@Jeremy A hash function is not the same thing at all as a hashtag! I see your point about study design though. I admit to not reading the whole of your question properly. – onestop Feb 16 '11 at 14:27
show 1 more comment

3 Answers

up vote 6 down vote accepted

Look up hash functions, for example at http://en.wikipedia.org/wiki/Hash_function

share|improve this answer

Why not just have a look-up table of numbers for each possible character in an email. Then concatenate the numbers to form a seed. For example,

A 1
B 2
C 3
....
@ 27
....

So abc@ccc, would be converted to 12327333. This would give you a unique seed for each person. You would then use this to generate the 1, 2, 3, 4.


From your question, it looks like you don't mind a "quick and dirty solution". One problem with my solution is that email addresses aren't random - for example you will probably get very few email addresses that contain the letter "z", but all email addresses contain "@".

share|improve this answer
A minor note about the above method is that there are a bunch of valid characters in email addresses - punctuation in particular - that you would want to consider if you were doing this. – dsolimano Feb 16 '11 at 14:51
@dsol: I agree. You could easily be caught out with a "+" in an email address. For a quick and dirty solution, I would probably just skip any punctuation characters that I hadn't specified in my look-up table. – csgillespie Feb 16 '11 at 14:59

You could try converting each character to an ascii number, multiplying them all together to force overflow, and then performing a modulus operation on the least significant digits. If this is not pseudo-random enough, you can perform a bit-shift the numbers a bit...

-Ralph Winters

share|improve this answer
1  
Multiplying is not the best idea, I think. Especially if your initial overflow is the regular one - modulo some power of 2. You will get a lot of factors that are even, so most of your lower bits will be 0. Adding the numbers together instead would already be a lot better. If you need even better randomness, use some sort of hash function and use any bits of the result. If you want it to be difficult to guess anything about the outcome for people other than you, use a salted strong cryptographic hash function. – Erik P. Feb 16 '11 at 17:17
Agreed. Just wanted to suggest idea to illustrate bit shifting in order to generate (roughly) pseudo-random numbers. – Ralph Winters Feb 17 '11 at 18:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.