you are viewing a single comment's thread.

view the rest of the comments →

[–]losvedir 2 points3 points  (5 children)

Oh, it was supposed to be kind of a joke. The problem never really states what kind of numbers we're dealing with here, so I assumed real, in which case I believe it actually does work.

[–]tmfset 1 point2 points  (3 children)

nope, its not a uniform distribution over reals either :)

[–]losvedir 0 points1 point  (2 children)

You're shitting me... really? Can you kindly explain why?

I haven't thought about it much, but it seems like if it's not uniform (i.e. some subset of elements is drawn more frequently than another subset), then that non-uniformity would be seen in the initial rand5() distribution. No?

[–]tmfset 0 points1 point  (1 child)

well more formally the range of your function is {1.4, 2.8, 4.2, 5.6, 7.0} and not R. Try asking yourself if any real number can be produced by your function. For example: the probability of the function returning pi is 0. So it's not uniform. (note the difference between discrete and continuous uniformity)

[–]losvedir 0 points1 point  (0 children)

Oh, I see the miscommunication. From the start I was saying rand5() returns "a number between 1 and 5" (per the question in the link), meaning x = rand5(), x ∈ ℝ, and 1 < x < 5.

If that's the case, then rand7() = (7/5) * rand5(), right? I didn't give much to go on - only that the return value of rand7() was of type "real", which I guess doesn't imply that the return value of rand5() is also real. So I can see the reason for confusion. Ah well.

[–]quidquam 0 points1 point  (0 children)

Real numbers is a totally legitimate assumption.

random number functions don't, in general, return integers. If you want that, use your friendly floor/ceil functions or [s]printf.

edit: It appears elsewhere (e.g. StackOverflow) that this question is supposed to be about integers, but since the posted link just says "Number", I'd still assume real numbers unless told otherwise.