zoukankan      html  css  js  c++  java
  • 【代码笔记】iOS-产生随机字符串

    一,代码:

    复制代码
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        NSLog(@"---产生随机字符串---%@",[self generateTradeNO]);
        
    }
    //产生随机字符串
    - (NSString *)generateTradeNO
    {
        static int kNumber = 15;
        
        NSString *sourceStr = @"0123456789ABCDEFGHIJKLMNOPQRST";
        NSMutableString *resultStr = [[NSMutableString alloc] init];
        srand(time(0));
        for (int i = 0; i < kNumber; i++)
        {
            unsigned index = rand() % [sourceStr length];
            NSString *oneStr = [sourceStr substringWithRange:NSMakeRange(index, 1)];
            [resultStr appendString:oneStr];
        }
        return resultStr;
    }
    复制代码

     

    二,输出:

    2015-10-23 10:04:22.908 产生随机字符串[974:46634] ---产生随机字符串---DQA5AGLNIBD52KQ

     

     
  • 相关阅读:
    CSPS模拟 57
    CSPS模拟 56
    CSPS Oct目标
    CSPS模拟 55
    CSPS模拟 54
    CSPS模拟 53
    和manacher有关的乱写
    CSPS模拟 52
    CSPS模拟 51
    Git和代码规范
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/7063141.html
Copyright © 2011-2022 走看看