Skip to content

Instantly share code, notes, and snippets.

@pvdz
Created July 2, 2015 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pvdz/3bbe2333fadda54da93f to your computer and use it in GitHub Desktop.
Save pvdz/3bbe2333fadda54da93f to your computer and use it in GitHub Desktop.
get randomly reordered 1234 (or abcd) without using arrays
var a = 'a', b = 'b', c = 'c', d = 'd';
a = 'a';
var r = RANDOM();
if (r < .5) {
b = a;
a = 'b';
}
r = RANDOM();
if (r < .33) {
c = b;
b = a;
a = 'c';
} else if (c < .66) {
c = b;
b = 'c';
}
r = RANDOM();
if (r < .25) {
d = c;
c = b;
b = a;
a = 'd';
} else if (c < .5) {
d = c;
c = b;
b = 'd';
} else if (c < .75) {
d = c;
c = 'd';
}
return a+b+c+d;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment