Forum Discussion
geoffcamp
14 years agoContributor
You're right, it doesn't work
I think this is because the function Math.random() returns a random number between 0 and just under 1. You've then got this as an integer, so it's always returning zero - hence the first branch (1 horse) is always being taken.
If you make the change to the line
intRandNum = Math.random()
so that it's
intRandNum = Math.random()*100
then this will, fairly obviously, multiply the generated value by 100, and give you a number between 0 and 99.
One other small change I think you'll need to make is replace the occassions where you have "intRandNumHorses" with "intRandNum".
This should then, hopefully, give you the results you're looking for.
Cheers,
Geoff
I think this is because the function Math.random() returns a random number between 0 and just under 1. You've then got this as an integer, so it's always returning zero - hence the first branch (1 horse) is always being taken.
If you make the change to the line
intRandNum = Math.random()
so that it's
intRandNum = Math.random()*100
then this will, fairly obviously, multiply the generated value by 100, and give you a number between 0 and 99.
One other small change I think you'll need to make is replace the occassions where you have "intRandNumHorses" with "intRandNum".
This should then, hopefully, give you the results you're looking for.
Cheers,
Geoff