Skip to content

Instantly share code, notes, and snippets.

@wookiecooking
Created March 20, 2015 18:42
Show Gist options
  • Save wookiecooking/36b60d8151bfddcf7056 to your computer and use it in GitHub Desktop.
Save wookiecooking/36b60d8151bfddcf7056 to your computer and use it in GitHub Desktop.
Random Generator
var Arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0];
var AArr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
var i = 0;
var Dump = [];
function isPrime(n) {
// If n is less than 2 or not an integer then by definition cannot be prime.
if (n < 2) {return false}
if (n != Math.round(n)) {return false}
// Now assume that n is prime, we will try to prove that it is not.
var isPrime = true;
// Now check every whole number from 2 to the square root of n. If any of these divides n exactly, n cannot be prime.
for (var i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0) {isPrime = false}
}
// Finally return whether n is prime or not.
return isPrime;
}
function randNum() {
return Arr[Math.floor(Math.random() * Arr.length)];
}
function doIt() {
while(i <= 50) {
i++
if(isPrime(randNum())) {
Dump.push(AArr[randNum()]);
} else
Dump.push(randNum())
}
}
doIt()
console.log(Dump.toString())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment