I was looking for a better way to generate random numbers in swift.
I did some research and found that the majority of pseudo-random number generators get the current time value and use the reminder operator (sometimes plus an integer value) to return a very low quality casual number.
e.g.
(timevalue % (upperBound - lowerBound)) + lowerBound
But this gives us a pseudo-fake number.
Is there any other way to generate better random numbers?
I would also like to create a "polar" random number generator:
polarRandom(between: NSRange, strength: CGFloat) -> Int
which returns random numbers in the range but with a higher probability (determined by strength
) of returning values near the upper and lower bounds.
And a middle polar generator which has a higher probability (always determined by strength
) of returning numbers near the middle part of the range:
middlePolarRandom(between: NSRange, strength: CGFloat) -> Int
Please don't blame me for the names of this functions, I didn't sleep well last night...
Any advice is appreciated : )
Aucun commentaire:
Enregistrer un commentaire