I am trying to understand how to use rand to do this. if there were two players for example player a and player b and the computer had to be one and the human the other. How would i implement this?
Asked
Active
Viewed 88 times
1 Answers
-2
[:computer, :player].shuffle.first
will give you on random who is first.

hahcho
- 1,369
- 9
- 17
-
2`sample` is more adequate – bjhaid Jul 19 '14 at 16:07
-
the tutorial i am following uses this – user3684357 Jul 19 '14 at 16:10
-
cpu = rand() > 0.5 ? 'X' : 'O' user = @cpu == 'X' ? 'O' : 'X' – user3684357 Jul 19 '14 at 16:11