no, it's not the same. the multiplications are needed so that no combination happens more than once (which would bias the probabilities). i came up with that after i have seen julzmighty's solution and after some trial and error. i tried to find a version which doesn't need while() or if().

what is rand() in your example? you must only use rand5().