首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏猿人谷

    oc 中随机数的用法(arc4random() 、random()、CCRANDOM_0_1()

    1)、arc4random() 比较精确不需要生成随即种子        使用方法 :                  通过arc4random() 获取0到x-1之间的整数的代码如下:                  int value = arc4random() % x;                   获取1到x之间的整数的代码如下:                  int value = (arc4random 个人来说我首选arc4random() ,原因就是它是一个真正的伪随机算法,而且范围是rand()的两倍。 num2 { int startVal = num1*10000; int endVal = num2*10000; int randomValue = startVal +(arc4random

    3.7K80发布于 2018-01-17
  • 来自专栏coding...

    swift 3.0 基础练习 面向对象 类

    age :Int = 0 //初始化随机姓名和年龄 override init() { name = String(format: "%c%c%c", 65 + arc4random ()', 65 + arc4random()', 65 + arc4random()') age = Int( arc4random() % 10 + 18 ) }

    38530发布于 2018-08-23
  • 来自专栏码农的生活

    ios生成三种随机数方法

    int i = arc4random() % 5 ; 注: rand()和random()实际并不是一个真正的伪随机数发生器,在使用之前需要先初始化随机种子,否则每次生成的随机数一样。 arc4random() 是一个真正的伪随机算法,不需要生成随机种子,因为第一次调用的时候就会自动生成。而且范围是rand()的两倍。 精确度比较:arc4random()  > random()  >  rand()。 常用方法:arc4random  1、获取一个随机整数范围在:[0,100)包括0,不包括100 int x= arc4random() % 100; 2、  获取一个随机数范围在:[500,1000] :(int)fromto:(int)to {     return (int)(from + (arc4random() % (to – from + 1))); }

    3.4K40发布于 2021-10-29
  • 来自专栏進无尽的文章

    基础篇- iOS开发中常用的数学函数

    unsigned)time(0)); //不加这句每次产生的随机数不变 int i = rand() % 5; srandom(time(0)); int i = random() % 5; int i = arc4random arc4random() 是一个真正的伪随机算法,不需要生成随机种子, 因为第一次调用的时候就会自动生成。而且范围是rand()的两倍。 在iPhone中,RAND_MAX是0x7fffffff (2147483647),而arc4random()返回的最大值则是 0x100000000 (4294967296)。 精确度比较:arc4random() > random() > rand()。 获取一个随机整数,范围在[from,to),包括from,不包括to -(int)getRandomNumber:(int)from to:(int)to { return (int)(from + (arc4random

    1.6K31发布于 2018-09-12
  • 来自专栏一“技”之长

    iOS流布局UICollectionView系列一——初识与简单使用UICollectionView

    dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];     cell.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];     return cell; } / ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];     UICollectionViewCell dequeueReusableCellWithReuseIdentifier:@"cellid" forIndexPath:indexPath];     cell.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];     return cell; } 效果如下

    4.4K20发布于 2018-08-16
  • 来自专栏正则

    iOS本地动态验证码生成

    () % 256 / 256.0 green:arc4random() % 256 / 256.0 blue:arc4random() % 256 / 256.0 alpha:1.0]; #define kLineCount 6 #define kLineWidth 1.0 #define kCharCount 6 #define kFontSize [UIFont systemFontOfSize:arc4random ; //随机从数组中选取需要个数的字符串,拼接为验证码字符串 for (int i = 0; i < kCharCount; i++)     { NSInteger index = arc4random () % (int)rect.size.width;         pY = arc4random() % (int)rect.size.height; CGContextMoveToPoint( context, pX, pY); //设置线终点         pX = arc4random() % (int)rect.size.width;         pY = arc4random

    85510发布于 2021-05-10
  • 来自专栏Elton的技术分享博客

    生成随机数

    但是Objective-C并没有提供相关函数,好在C提供了rand(), srand(), random(), srandom(), arc4random()几个函数 // Get random number between 0 and 500 int x = arc4random() % 100; // Get random number between 500 and 1000 int y = ( arc4random() % 501) + 500); arc4random()的好处是不用seed ---- Previous 给TableView

    3.6K30发布于 2021-01-26
  • 来自专栏梧雨北辰的开发录

    iOS动画-CALayer隐式动画原理与特性

    self.view.layer addSublayer:_colorLayer]; } - (IBAction)changeColor:(UIButton *)sender{ CGFloat red = arc4random () % 255 / 255.0; CGFloat green = arc4random() % 255 / 255.0; CGFloat blue = arc4random() % 255 transform, M_PI_2); self.colorLayer.affineTransform = transform; }]; CGFloat red = arc4random () % 255 / 255.0; CGFloat green = arc4random() % 255 / 255.0; CGFloat blue = arc4random() % 255 () % 255 / 255.0; CGFloat green = arc4random() % 255 / 255.0; CGFloat blue = arc4random() % 255

    5.2K51发布于 2019-04-25
  • 来自专栏全栈程序员必看

    IOS基金会_ UICollectionView简单易用

    dequeueReusableCellWithReuseIdentifier:_CELL forIndexPath:indexPath]; cell.backgroundColor = [UIColor colorWithRed:((arc4random ()%255)/255.0) green:((arc4random()%255)/255.0) blue:((arc4random()%255)/255.0) alpha:1.0f]; return collectionView cellForItemAtIndexPath:indexPath]; cell.backgroundColor = [UIColor colorWithRed:((arc4random ()%255)/255.0) green:((arc4random()%255)/255.0) blue:((arc4random()%255)/255.0) alpha:1.0f]; } //返回这个

    55610编辑于 2022-07-06
  • 来自专栏码农的生活

    objective-c产生随机数的方法

    //arc4random() 比较精确不需要生成随即种子 //通过arc4random() 获取0到x-1之间的整数的代码如下: int value = arc4random() % x; / /获取1到x之间的整数的代码如下: int value = (arc4random() % x) + 1; //CCRANDOM_0_1() cocos2d中使用 ,范围是[0,1] float

    91130发布于 2021-10-29
  • 来自专栏iOSer成长记录

    iOS-关于随机数总结rand()random()drand48()arc4random()rac4random_uniform(int upper_bound)实例应用

    C语言随机函数rand() random() drand48() OC随机函数arc4random() arc4random_uniform() rand() // 生成m~n之间的随机整数 -(int isSranded) { isSranded = YES; srand48(time(0)); } return drand48(); } arc4random () // 生成m~n之间的随机整数 -(int)arc4randomFrom:(int)m to:(int)n{ return m + arc4random()%(n - m + 1); }

    1.3K40发布于 2018-06-29
  • 来自专栏進无尽的文章

    动画| 金币抛入红包动画详解

    intValue] % 2 + 1]]]; //初始化金币的最终位置 coin.center = CGPointMake(CGRectGetMidX(self.view.frame) + arc4random ()%40 * (arc4random() %3 - 1) - 20, CGRectGetMidY(self.view.frame) - 20); coin.tag = [i intValue] coin.layer.position.x; //终点x CGFloat positionY = coin.layer.position.y; //终点y int fromX = arc4random UIScreen mainScreen].bounds.size.height + coin.frame.size.height; //y轴以屏幕高度为准 int fromY = arc4random /////////////////////////////////////////////////// //图像由大到小的变化动画 CGFloat from3DScale = 1 + arc4random

    1.8K50发布于 2018-09-12
  • 来自专栏全栈程序员必看

    Cocos2d-x 水果忍者划痕效果

    max_lineWidth = 5; float min_lineWidth = 1; int alpha_min = 10; int alpha_max = 200; int R = arc4random ()%255; int G = arc4random()%255; int B = arc4random()%255; int pointListCount = pointList.size(

    41110编辑于 2022-07-09
  • 来自专栏一“技”之长

    iOS第三方左对齐布局类——UICollectionViewLeftAlignedLayout

    UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{ return CGSizeMake(arc4random dequeueReusableCellWithReuseIdentifier:@"cellID" forIndexPath:indexPath]; cell.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1]; return cell; } @end

    2.3K20发布于 2018-08-15
  • 来自专栏雨尘分享

    iOS 动画基础总结篇

    ()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256/ 255.0 alpha:1.0]; } }]; [UIView ) { UIView *view = self.viewArray[6]; view.backgroundColor = [UIColor colorWithRed: arc4random ()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256/ 255.0 alpha:1.0]; } }] UIView *view = self.viewArray[7]; view.backgroundColor = [UIColor colorWithRed: arc4random ()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256/ 255.0 alpha:1.0]; } }]

    1.4K50发布于 2018-06-07
  • 来自专栏一“技”之长

    iOS9新特性——堆叠视图UIStackView

            UIView * view = [[UIView alloc]init];         view.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];         [array addObject ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];     [stackView addArrangedSubview         UIView * view = [[UIView alloc]init];         view.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1];         float height 

    3.7K11发布于 2018-08-15
  • 来自专栏吃猫的鱼个人博客编程笔记

    【代码笔记】c语言实现生成随机数

    arc4random() 函数: 这个函数是 C 语言封装的一个比较智能的随机函数,我们只要调用这个函数,就会产生随机数,不用设置随机种子,而且用法很简单: int arc_rand = arc4random (); printf("arc_rand = %d\n", arc_rand); 产生随机 a-b的数值 arc4random() % (b - a + 1) + a; 本文共 670 个字数,平均阅读时长

    1.8K40编辑于 2023-02-02
  • 来自专栏iOS开发攻城狮的集散地

    iOS CoreData (一) 增删改查

    //2.根据表Student中的键值,给NSManagedObject对象赋值 student.name = [NSString stringWithFormat:@"Mr-%d",arc4random ()%100]; student.age = arc4random()%20; student.sex = arc4random()%2 == 0 ? @"美女" : @"帅哥" ; student.height = arc4random()%180; student.number = arc4random()%100 //

    1.8K70发布于 2018-05-22
  • 来自专栏一“技”之长

    iOS录屏框架ReplayKit的应用总结

    UITouch *> *)touches withEvent:(UIEvent *)event { self.view.backgroundColor = [UIColor colorWithRed:arc4random ()%255/255.0 green:arc4random()%255/255.0 blue:arc4random()%255/255.0 alpha:1]; } // 录屏结束的回调 - (void

    3.8K30发布于 2020-05-13
  • 来自专栏落影的专栏

    iOS的异步处理神器——Promises

    fulfill, FBLPromiseRejectBlock reject) { BOOL success = arc4random 对象后面挂一个then方法,表示这个Promise执行完毕之后,要继续执行的任务: [[[FBLPromise do:^id _Nullable{ BOOL success = arc4random NSString *> *)pay:(NSString *)payParam { return [FBLPromise do:^id _Nullable{ BOOL success = arc4random - (FBLPromise<NSString *> *)work1 { return [FBLPromise do:^id _Nullable{ BOOL success = arc4random (FBLPromise<NSNumber *> *)work2 { return [FBLPromise do:^id _Nullable{ BOOL success = arc4random

    3.6K20发布于 2019-07-15
领券