title pretty much explains it, i want to use the value of a slider as the range - I know I have to convert the value to an integer and such, but my attempts keep yielding errors. Quickest way to do it?
First, forget about arc4random. It's a waste of your time. Use random().
Show your code and tell what errors you're getting. You may need to typecast the slider.value because it returns a float. Cast it to int.
int xRandoms = (int)(randomBallBasicXChange.value);
randomicityXresult = 1 + arc4random() % xRandoms;
Right. You can't use the modulus operator with floats.
You should still dump arc4random(). It's slower than random() and for most uses will give you no better results. I assume you're not doing encryption with the value of your slider.
on the guy who made the most popular iphone book, he has a blog and he compared arc4random() and rand()
he had comparisions and in the comments someone said rand() was quicker and there is math there and it shows that realistically you aren't getting any performance boosts from using it as well as the fact you don't have to seed arc4random and the results given are almost identical, if you haven't seen the blog post i can look around on the internet, but as i said its on the blog for one of the two authors of that book
on the guy who made the most popular iphone book, he has a blog and he compared arc4random() and rand()
he had comparisions and in the comments someone said rand() was quicker and there is math there and it shows that realistically you aren't getting any performance boosts from using it as well as the fact you don't have to seed arc4random and the results given are almost identical, if you haven't seen the blog post i can look around on the internet, but as i said its on the blog for one of the two authors of that book
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: rand(); 10000 repetitions
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: time = 3.73298 secs
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: random(); 10000 repetitions
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: time = 1.44297 secs
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: arc4random(); 10000 repetitions
Thu Sep 17 14:18:08 unknown testarc4random[141] <Warning>: time = 11.064 secs
#define REPETITIONS (10 * 1000)
- (void)testRandom
{
{
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
for (int i = 0; i < REPETITIONS; i++)
{
int j = rand();
}
NSTimeInterval end = [NSDate timeIntervalSinceReferenceDate];
NSLog(@"rand(); %d repetitions", REPETITIONS);
NSLog(@"time = %g secs", (end - start) * 1000.0);
}
{
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
for (int i = 0; i < REPETITIONS; i++)
{
int j = random();
}
NSTimeInterval end = [NSDate timeIntervalSinceReferenceDate];
NSLog(@"random(); %d repetitions", REPETITIONS);
NSLog(@"time = %g secs", (end - start) * 1000.0);
}
{
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
for (int i = 0; i < REPETITIONS; i++)
{
int j = arc4random();
}
NSTimeInterval end = [NSDate timeIntervalSinceReferenceDate];
NSLog(@"arc4random(); %d repetitions", REPETITIONS);
NSLog(@"time = %g secs", (end - start) * 1000.0);
}
}
does rand() or random() work faster if they haven't been seeded?
also i remember reading that rand() and random() will end up getting you the same pattern of numbers over time unles you keep seeding, so surley when thats taken into account that could affect the results?