密码生成器+随机数生成器

xiaoxiao2021-02-28  193

随机数生成器

0~RAND_MAX之间的随机数程序

#include <iostream> #include <stdlib.h> #include <time.h> using namespace std; int main() { srand((unsigned)time(NULL)); for(int i = 0; i < 10; i++ ) cout << rand() << '\t'; cout << endl; return 0; } 产生一定范围随机数的通用表示公式 要取得[a,b)的随机整数,使用(rand() % (b-a))+ a; 要取得[a,b]的随机整数,使用(rand() % (b-a+1))+ a; 要取得(a,b]的随机整数,使用(rand() % (b-a))+ a + 1; 通用公式:a + rand() % n;其中的a是起始值,n是整数的范围。 要取得a到b之间的随机整数,另一种表示:a + (int)b * rand() / (RAND_MAX + 1)。 要取得0~1之间的浮点数,可以使用rand() / double(RAND_MAX)。

密码生成器

#include<stdio.h> #include<stdlib.h> #include<time.h> int main() { char pool[]= { '0','1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j', 'k','l','m','n','o','p','q','r','s','t', 'u','v','w','x','y','z','A','B','C','D', 'E','F','G','H','I','J','K','L','M','N', 'O','P','Q','R','S','T','U','V','W','X', 'Y','Z' }; srand(time(0)); char pwd[9]; pwd[6]='\0'; //freopen("out.txt","w",stdout); for(int i,j=1;j<=200;j++){///密码数量 i=0; while(i!=6) pwd[i++]=pool[rand()%sizeof(pool)]; printf("%s\n",pwd); } return 0; }

转载请注明原文地址: https://www.6miu.com/read-1119504.html

最新回复(0)