Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
Created January 7, 2012 21:59
Show Gist options
  • Select an option

  • Save codeswimmer/1576189 to your computer and use it in GitHub Desktop.

Select an option

Save codeswimmer/1576189 to your computer and use it in GitHub Desktop.
iOS: Using arc4random() to get a floating point value between 0 and a given maximum value
/*
Using arc4random() to get a floating point value between 0 and a given maximum value. Note that this produces a value that is double the precision of using rand().
*/
-(double)randomValueFromZero:(double)toValue
{
return double val = floorf(((double)arc4random() / toValue) * 100.0f);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment