生成四位随机数,数字不重复
2012-11-16 23:44
225 查看
发现以前写的算法,过段时间不去看竟然忘得一干二净。
使用c语言写的,算是做个记录,免得以后忘记。
使用c语言写的,算是做个记录,免得以后忘记。
#include <math.h> #include <time.h> #include <stdlib.h>
int GetRand() { int sum = 4,number = 0,tem = 0; int arrr[10]; memset(arrr,-1,10 * 4); bool isFirst = true; srand(time(NULL)); while (sum > 0) { tem = rand() % 10; if (arrr[tem] == -1) { if (tem == 0) { if (isFirst); else { arrr[tem] = tem; sum --; } } else { arrr[tem] = tem; number += tem * pow(10.0,sum - 1); isFirst = false; sum --; } } } return number; }
相关文章推荐
- java中随机生成随机数及不重复的随机数字
- 生成四位不重复随机数
- java生成四位随机数,包含数字和字母 区分大小写,特别适合做验证码,android开发
- [置顶] java生成四位随机数,包含数字和字母 区分大小写,特别适合做验证码,android开发
- java生成四位随机数,包含数字和字母
- 如何生成8位无重复的随机数(数字+字母)
- js随机数1到10生成不重复的
- PHP 生成一定数量的不重复随机数
- JS生成不重复随机数
- jsp生成四位数字的验证码
- 生成 [0-n) 个不重复的随机数
- python生成某区间内不重复的随机数
- C# 随机数生成避免重复
- 生成不重复的随机数序列
- .Net 生成不重复的随机数
- java中生成无重复随机数的2种方法
- 不重复随机数生成;O(1)时间;二进制哈希判重;
- asp实现生成由数字,大写字母,小写字母指定位数的随机数
- C# Random 生成不重复随机数
- T-SQL生成X个不重复的Y位长度的随机数