# Random script that isn't actually random

As a little joke in the office someone wanted a script that randomly picks a name, and said person will make a round of drinks.

Let's call the people John, Jeff, Emma, Steve and Julie.

I thought it would be funny to make a script that seems random at a quick glance, but actually always gives the same person as the output (Up to you who you choose).

Highest voted answer wins after a week

And the winner is....

Paul R with (currently) 158 votes.

The answers here are great, and if anyone else has any other ideas what haven't been posted yet, please add them, I love reading through them.

• xkcd.com/221 – AstroCB Jun 16 '14 at 19:30
• @AstroCB one of my favourites. Right behind bobby tables. – Cruncher Jun 16 '14 at 20:08
• It seems like it would be sneakier if it was random, except for never picking one person. – Brendan Long Jun 16 '14 at 22:52
• @AstroCB this one is also fantastic: dilbert.com/strips/comic/2001-10-25 – gilbertohasnofb Jun 18 '14 at 10:08
• I went through the first page: most answers always choose John, 2nd highest is Julie, Jeff is chosen rarely and Steve by 1. Even Ray got chosen by one but nobody chose Emma. Moral of the story: when standing in a line to decide randomly who will buy the drinks, name yourself Emma. – Miserable Variable Jul 15 '14 at 19:33

# PHP with microtime for extra randomisation

$names = array('John', 'Jeff', 'Emma', 'Steve', 'Julie');$choosenPerson = false;
while($choosenPerson === false){ // Use microtime for a very random value:$uid= substr(microtime(true), 0, 1);
if( isset($names[$uid]) ){ $choosenPerson =$names[$uid]; } }  Im going for the microtime misconception. Microtime suggests that we have a very random factor, but im taking the first character which is 1. So for the upcomming years, Jeff will loose a lot of money. After that it'll be Emma :) # Python 2 import random names = ["John, Jeff, Emma, Steve, Julie"] print random.choice(names)[:3]  Surprised nobody did something like this before. "John, Jeff, Emma, Steve, Julie" is one string. Super obvious but whatevs • This doesn't print John, it prints Joh – pppery Nov 2 '15 at 14:04 # Python def iterate(names): for name in names: yield lambda:name import random print random.choice(list(iterate("John Jeff Emma Steve Julie".split())))()  Sorry, Julie! The name variable int the iterate function is the same one as in the lambdas, so every lambda evaluates the the last name, Julie. BASH / Coreutils Quite a beginner at CG, but worth a shot: RANDOM=$$; a=RANDOM b=9 c=expr a % b  echo c $$ is the PID of the running shell, so the number should be always the same • What happens when you restart the shell? – Knerd Jun 16 '14 at 12:57 • Another number is printed, but always the same for that session – german_guy Jun 16 '14 at 12:59 • This does not work because I saved these commands in a script, and bash pick-someone-b.bash uses a different PID each time. – kernigh Jun 16 '14 at 19:34 • Sorry... while doing the &&-> change the preview of the hidden text fooled me and showed only 2$s... now there are 4 of then... can you check what happens in your browser with the preview of  while editing? If it is not a local browser problem, maybe StackExchange should get a hint about this... (Plus Megawink vom Niederrhein!) – user19214 Jun 17 '14 at 22:12
• Maybe it went wrong because I did it on the phone. Now it seems to work. Grüße an den Niederrhein ;) – german_guy Jun 18 '14 at 7:00

JavaScript:

function ActuallyNotRandom() {
this.names = ["John", "Jeff", "Emma", "Steve", "Julie"];

this.choose = function()
{
return this.names[Math.random(this.names.length) * 0];
}

return this.choose();
}

console.log("Random person: " + ActuallyNotRandom());


Pretty straightforward, takes a list of names, makes a random number between 0 and the number of names in the list, and then multiplies it by 0 to always return 0. Will therefore actually always return the first name in the list and display it to console.

• The *0 is very obvious. I suggest Math.floor(Math.random()) to hide it just a bit better – Martijn Jun 17 '14 at 12:09
• Not that it matters after multiplying by 0, but Math.random(n) doesn't return return what you think it does. – Dennis Oct 3 '14 at 2:00