Reputation: 223
As the title suggest, would hope to generate a random float in the range between 0.3 < x < 0.7.
I currently using while loop to check a random float whether its in that range. I was wondering whether there is a better method to do this.
Upvotes: 2
Views: 10139
Reputation: 14972
0.3 + random-float 0.4
will give you 0.3 <= x < 0.7.
If you really don't want 0.3, I guess you can always loop that one out. I'm not sure if there is a better way.
Upvotes: 6