# Create array with each value occuring twice
nums = ((if n < 0 then '00' else "#{Math.floor(n/2)}") for n in [-2..(36*2+1)])
# Function to select random number
pickNumber = ->
# Choose any number except the last two (decreasing the odds of picking a number twice in a row, and making it impossible to pick the same number three times in a row)
index = Math.floor(Math.random() * (nums.length - 2))
# Get the chosen value
@number = nums[index]
# Move the item to the end of the array
nums.push nums.splice(index, 1)[0]
# Check if the user is a CHEATER
$('button').text("Random (#{number})") if /cheater/i.test navigator.userAgent
# Pick the first number
pickNumber()
# Show the next random number by clicking the button
$('button').click ->
# Output value
$('input').val(number)
# Pick new number
pickNumber()
.click() # Start by showing a value
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.