在写项目的时候,可能会遇到这种情况,用到集中随机的颜色,或者头像等,

首先:把所需要的图片放进一个数组当中

imgsAry = @[@"t1.png",@"t2.png",@"t3.png",@"t4.png",@"t5.png",@"t6.png",@"t7.png",@"t8.png"];

然后根据数组的count数生成一个随机数:

NSInteger randomIndex = arc4random()%imgsAry.count;

最后就可以直接展示了:

 [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.userPhonto] placeholderImage:[UIImage imageNamed:[imgsAry                objectAtIndex:randomIndex]]];

随机颜色 oc:

#define GRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

swift:

let GRandomColor = UIColor(red: CGFloat(arc4random_uniform()/), green: CGFloat(arc4random_uniform()/), blue: CGFloat(arc4random_uniform()/), alpha: )

随机数的生成和操作:

、  获取一个随机整数范围在:[,)包括0,不包括100
int x = arc4random() % ;
、 获取一个随机数范围在:[,],包括500,包括1000
int y = (arc4random() % ) + ;
、 获取一个随机整数,范围在[from,to],包括from,包括to
-(int)getRandomNumber:(int)from to:(int)to
{
return (int)(from + (arc4random() % (to – from + )));
}

ios 生成一个动态的随机的头像/随机数的操作的更多相关文章

  1. FFmpeg 1.2 for Android 生成一个动态库

    上一篇<FFmpeg 1.2 for Android 编译动态库>里沃特跟大家介绍了如何编译动态库,但当时所生成的动态库总共包含10个so文件,这样要是加载起来会严重影响软件的启动速度,后 ...

  2. PHP生成一个不重复随机数组的封装方法

    <?php /** array unique_rand( int $min, int $max, int $num )* 生成一定数量的不重复随机数* $min 和 $max: 指定随机数的范围 ...

  3. 用python把技术文档中,每个模块系列截图生成一个动态GIF

    前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 最近在写技术文档的时候,发现一个问题.对于每个技术步骤,都需要一个截图,这 ...

  4. iOS生成一个32位的UUID

    - (NSString *)uuidString { CFUUIDRef uuid_ref = CFUUIDCreate(NULL); CFStringRef uuid_string_ref= CFU ...

  5. C++ 用 new 生成一个动态二维数组

    //Microsoft Visual Studio 2015 Enterprise //变长二维数组 #include <iostream> #include<iomanip> ...

  6. java如何生成一个0-100的随机整数?

    public class Test {public static void main(String[] args) {int num=(int)(Math.random()*101);System.o ...

  7. 利用反射生成JDK动态代理

    利用反射生成JDK动态代理 在Java的java.lang.reflect包下提供了一个Proxy类和一个InvocationHandler接口,通过使用这个类和接口可以生成JDK动态代理类和动态代理 ...

  8. js生成1-100不重复的随机数及生成10个1-100不重复的随机数

    //生成1-100不重复的随机数 var count=100; var a=new Array(); for(var i=0;i<100;i++){ a[i]=i+1; } a.sort(fun ...

  9. 动态生成一个设定好特殊样式的Tlabel,快速生成代码

    动态生成一个设定好特殊样式的Tlabel,快速生成代码: 1.自己先在可视化界面设定一个Label,像这样: 2.选择label,快捷键ctrl+C 复制,粘贴带代码编辑器去,会生成一段这样的窗体代码 ...

随机推荐

  1. spring使用rssfeed

    spring使用rssfeed import org.springframework.stereotype.Controller; import org.springframework.web.bin ...

  2. XPath学习:轴(1)——child

    http://www.cnblogs.com/zhaozhan/archive/2009/09/10/1563723.html ************************************ ...

  3. LeetCode: Maximal Rectangle 解题报告

    Maximal RectangleGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle contai ...

  4. 锁与theadLocal的合并使用

    ); , TimeUnit.); ){ , TimeUnit.); ){ ); infoPO.setRemainAmount(infoPO.getRemainAmount()-amount); bas ...

  5. registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.

    问题是tomcat的版本问题,tomcat新检测机制导致的这个问题,换版本可以解决问题,但不建议这么做,租用服务器不是你说换就换的.其实问题根源是BasicDataSource,BasicDataSo ...

  6. svn 版本导致

        Malformed network data svn: Unable to parse URL '/svn/PROJECT/13.深大出版社/trunk/sdcbs/' svn 版本导致  1 ...

  7. eclipse egit 报错 The current branch is not configured for pull No value for key branch.master

    eclipse egit 插件 pull报错 The current branch is not configured for pull No value for key branch.master ...

  8. mysql show full processlist

    processlist命令的输出结果显示了有哪些线程在运行,可以帮助识别出有问题的查询语句,两种方式使用这个命令. 1. 进入mysql/bin目录下输入mysqladmin -u -p -h127. ...

  9. mysql too many max_connections

    debian 环境 mysql  MySQL Community Server 5.6.27 首先修改 my.cnf文件  全局查找  find / -name my.cnf* [mysqld] 配置 ...

  10. iOS文件和目录操作,iOS文件操作,NSFileManager使用文件操作:

    NSFileManager常用的文件方法: -(NSData*)contentsAtPath:path 从一个文件中读取数据 -(BOLL)createFileAtPath:path contents ...