Skip to content

Instantly share code, notes, and snippets.

View charliechauri's full-sized avatar
🎯
Focusing

charliechauri charliechauri

🎯
Focusing
View GitHub Profile
@hamg26
hamg26 / rng-coinFlip.js
Last active May 20, 2019 04:44
You are provided this flip function: function flip() { return Math.random() >= 0.5; }. You must implement a randomNumber(n) function that generates a random number greater than or equal to 0, and less than input n. n must be greater than 0. n must be less than 1,000,000. Your only source of randomness must be the provided flip() function. You ca…
function flip() {
return Math.random() >= 0.5;
}
function randomNumber(n) {
if(n === undefined) throw new Error("n is required");
if(n <= 0) throw new Error("n must be greater than 0");
if(n > 1000000) throw new Error("n must be lower than 1,000,000");
// No need to further calculations