I'm trying to generate a random number that's between 0 and 1. I keep reading about arc4random()
, but there isn't any information about getting a float from it. How do I do this?
相关问题
- Multiple sockets for clients to connect to
- Core Data lightweight migration crashes after App
- What is the best way to do a search in a large fil
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
Use this to avoid problems with upper bound of arc4random()
Note that it is applicable for MAC_10_7, IPHONE_4_3 and higher.
by default produces a random number(float) between 0 and 1.
Random value in [0, 1[ (including 0, excluding 1):
A bit more details here.
Actual range is [0, 0.999999999767169356], as upper bound is (double)0xFFFFFFFF / 0x100000000.
This is extension for Float random number Swift 3.1
arc4random
has a range up to 0x100000000 (4294967296)This is another good option to generate random numbers between 0 to 1:
This function works for negative float ranges as well: