linux平台下如何用C随机的产生256个字符

linux平台下如何用C随机的产生256个字符,第1张

#include "stdio.h"

#include "stdlib.h"

#include "time.h"/*需引用的头文件*/

int main(){

srand((unsigned)time(NULL))/*随机种子*/

int a=0,b=255//ASCII 字符范围

int i

for (i=0i<256i++){

int n=rand()%(b-a+1)+a/*n为a~b之间的随机数*/

printf("%c ",n)

}

return 0

}

linux内核自1.3.30版本以来实现了一个随机数产生器,从理论上说它能产生真正的随机数,该随机数产生器是从设备驱动收集电路上的环境噪音放入熵池,它的实现代码在drivers/char/random.c中,自己去看吧

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

int main()

{

int i,j

srand(time(0))

for( i = 0i <1000i++)

for(j = 0i <100i++){

printf("%3d",rand()%100+1)

printf("\n")

}

return 0

}


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/8570805.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-18
下一篇2023-04-18

发表评论

登录后才能评论

评论列表(0条)

    保存