-2

labelGen.text = [self, arc4random() % 1000]

give's me error => "Could not find an overload for '%' that accepts the supplied arguments"

Help me please

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • 1
    Not exactly an answer, but you should use arc4random_uniform rather than arc4random with a modulo - https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man3/arc4random_uniform.3.html – Paulw11 Jun 08 '14 at 08:21
  • Yeah, don't use %, otherwise you'll get modulo bias anyway. For Swift, see [this existing question](http://stackoverflow.com/questions/24058195/what-is-the-easiest-way-to-generate-random-integers-within-a-range-in-swift) – Matt Gibson Jun 08 '14 at 08:26

1 Answers1

0

Though its not clear what you want to achieve, I think you want a random number as a string. You can get it as below.

NSUInteger random = arc4random()%1000;
labelGen.text = [NSString stringWithFormat:@"%d",random];

In you code,

labelGen.text = [self, arc4random() % 1000]

the arc4random() function is c function not Objective-C function, show you can not call it on self. Also this expression will give you unsigned int value not a NSString value.

kkumpavat
  • 452
  • 2
  • 10