Hacker News new | ask | show | jobs
by CorvusCrypto 3508 days ago
stuff like this can't help

var n = Double(arc4random_uniform(UInt32(weightTotal * 1000000.0))) / 1000000.0

2 comments

Yep totally, going to take another pass to try and make it faster. This was just a make it work experiment. Had a few fun troubles with random, but at the moment it just crawls :(.
Out of curiosity, what's wrong with that line? Why is it slow?
starting from inside the arc4random call you have double float multiplication, then cast to uint32, then the arc4rand call, then the double cast for the uint32 result and then a double float division. this adds up in instructions.