Created
April 27, 2009 22:06
-
-
Save beccasaurus/102769 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# randomly generate 0 or 1 ... you should get 1 about 10% of the time, 0 about 90% of the time | |
$ irb | |
>> rand | |
=> 0.534835738078545 | |
>> rand | |
=> 0.334280092272696 | |
>> rand * 10 | |
=> 2.22911939494193 | |
>> ( rand * 10 ).to_i | |
=> 0 | |
>> 15.times { puts ( rand * 10 ).to_i } | |
4 | |
5 | |
4 | |
7 | |
2 | |
5 | |
4 | |
7 | |
0 | |
0 | |
8 | |
9 | |
5 | |
2 | |
9 | |
=> 15 | |
>> puts "it randomly generates a number from 0 to 9 ..." | |
it randomly generates a number from 0 to 9 ... | |
=> nil | |
>> 15.times { num = ( rand * 10 ).to_i; num = 0 unless num == 1; puts num } | |
0 | |
0 | |
1 | |
0 | |
0 | |
0 | |
0 | |
0 | |
0 | |
0 | |
0 | |
1 | |
1 | |
0 | |
0 | |
=> 15 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment