Skip to content

Instantly share code, notes, and snippets.

@chuckwagoncomputing
Created September 7, 2013 03:03
Show Gist options
  • Save chuckwagoncomputing/6472465 to your computer and use it in GitHub Desktop.
Save chuckwagoncomputing/6472465 to your computer and use it in GitHub Desktop.
Random Selection Chance Counter
#!/usr/bin/env ruby
$randwins = 0
$swins = 0
$equal = 0
$tried = []
ARGV[0].to_i.times do
$times = 0
$num = rand(1..9)
$sel = rand(1..$num)
loop do
$times += 1
loop do
$randn = rand(1..$num)
break unless $tried.include?($randn)
end
if $randn == $sel
$tried = []
if $times > $sel
$swins += 1
elsif $times < $sel
$randwins += 1
else
$equal +=1
end
break
else
$tried.push($randn)
end
end
end
puts "random: #{$randwins}"
puts "sequential: #{$swins}"
puts "equal: #{$equal}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment