generating random values in iPhone

前端 未结 6 936
Happy的楠姐
Happy的楠姐 2020-12-20 00:18

I have used rand(). But it gives a specific value even after I restart application.

I have implemented following in my application.

- (void)viewDidLo         


        
6条回答
  •  一个人的身影
    2020-12-20 01:14

    I would do it like this:

    landscape:

    - (void)viewDidLoad {
    [super viewDidLoad];
    
    
    int x = arc4random()%480;
    int y = arc4random()%320;
    
    lblT.center=CGPointMake(x,y);
    }
    

    not landscape:

     - (void)viewDidLoad {
        [super viewDidLoad];
    
    
        int x = arc4random()%320;
        int y = arc4random()%480;
    
        lblT.center=CGPointMake(x,y);
        }
    

提交回复
热议问题