We looked at how random numbers work in JavaScript and built a page that displayed an image chosen randomly from a selection. The quotes inside quotes proved especially confusing.
I asked why do some images occur less frequently than others. If you think you know leave your answer as a comment.
Notes
random Image page
Subscribe to:
Post Comments (Atom)
2 comments:
em.. Because of the laws of probability?
Ok, i get it now, the first and last pic (pic0 and pic6) have less chance of showing up then the others. The random number generator generates a number between 0 and 1 and the number is rounded to a whole number, meaning if the number is say 0.49 it will be 0. 0 will only be the outcome if the number is between 0.0 and 0.49..., so in this particular case it will only ever be rounded down to 0, because the number generator will never produce a number below 0. on the other hand all the numbers in the middle can be gotten to by rounding up or down, but the number 1 has the same chance as the number 0 of coming up for a similar reason.
sorry for the rubbish explanation!
Post a Comment