zoukankan      html  css  js  c++  java
  • 随机数

        一个小小的随机数工具。。。。。。。

     1 self.view.backgroundColor = [UIColor yellowColor];
     2     
     3     UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 240, 60)];
     4     label.font = [UIFont boldSystemFontOfSize:30];
     5     label.text = @"点击开始随机";
     6     label.backgroundColor = [UIColor grayColor];
     7     label.textAlignment = NSTextAlignmentCenter;
     8     label.tag = 1;
     9     [self.view addSubview:label];
    10     [label release];
    11     
    12     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    13     btn.frame = CGRectMake(120, 180, 80, 40);
    14     btn.backgroundColor = [UIColor grayColor];
    15     [btn setTitle:@"开始" forState:UIControlStateNormal];
    16     [btn setTitle:@"停止" forState:UIControlStateSelected];
    17     [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    18     [self.view addSubview:btn];
    19 }
    20 
    21 - (void)btnClick:(UIButton *)sender
    22 {
    23     sender.selected = !sender.selected;
    24     
    25     if (sender.selected) {
    26         
    27         _timer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(timeRun) userInfo:nil repeats:YES];
    28         //启动时间器,让self每隔0.01秒执行一次timeRun
    29         
    30     } else {
    31         
    32         [_timer invalidate];
    33         //关闭时间器
    34     }
    35 }
    36 
    37 - (void)timeRun
    38 {
    39     int row = arc4random_uniform(8)+1;
    40     int num = arc4random_uniform(11)+1;
    41     
    42     UILabel *label = (UILabel *)[self.view viewWithTag:1];
    43     //通过tag找view
    44     
    45     label.text = [NSString stringWithFormat:@"%d%02d",row,num];
    46 }
  • 相关阅读:
    MySQL数据库表的设计和优化(上)
    MySQL性能优化最佳实践20条
    MySQL高性能优化指导思路
    MySQL 5.6 my.cnf优化后的标准配置(4核 16G Centos6.5 x64)
    MySQL优化之索引优化
    MySQL优化之SQL语句优化
    MySQL优化之配置参数调优
    Apache的ab测试
    FastCGI模式下安装Xcache
    除了用作缓存数据,Redis还可以做这些
  • 原文地址:https://www.cnblogs.com/Angelone/p/4384817.html
Copyright © 2011-2022 走看看