How to create a random Uniform Distribution between (but excluding) 0 and 10?

Just to try to prevent this thread being overwhelming for a newcomer, let me just highlight the straightforward answer:

10*(1-rand())

Analysis:

  • rand() is uniform from [0, 1)
  • 1-rand() is uniform from (0, 1]
  • 10*(1-rand()) is uniform from (0, 10]

This is a totally fine, simple answer. Is it perfectly uniformly distributed? Meh, maybe, maybe not but the chance that it matters for this use case is negligible.

22 Likes