文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>随机数

随机数

时间:2009-07-18  来源:tancotq

rand()返回一个 0- RAND_MAX(2147483647)之间的随机数 产生一个 X , X >=0, X<1, 可用rand()/(RAND_MAX + 1.0)   以下是个简单的程序: #include <stdlib.h>
#include <stdio.h>
#include <time.h>
int main()
{
        int i, j;
        srand((int)time(NULL));
        for (i = 0; i < 10; i++)
        {
                j = 1 + (int)(10.0 * rand() / (RAND_MAX + 1.0));
                printf("%d ", j);
        }
 printf("\n");
}
编译: gcc 3-3.c -o 3-3 [root@localhost math]# ./3-3
3 5 5 8 1 6 10 7 1 4
[root@localhost math]# ./3-3
9 8 4 3 9 3 1 6 5 6
[root@localhost math]# ./3-3
7 9 9 4 5 9 9 1 5 6
[root@localhost math]#
   
相关阅读 更多 +
排行榜 更多 +
GBox

GBox

系统软件 下载
影图照片编辑

影图照片编辑

游戏工具 下载
多友多书网站登陆

多友多书网站登陆

浏览阅读 下载