第1个回答 2006-09-11
楼主在哪看到C++里能用random,rnd这两个函数的?我只知道rand函数,是产生0-32768之间的随机整数的。
所以用rand()%n就可以生产0到n-1之间的随机整数。
想得到每次不同的结果,可以将系统时间作为randomize的参数来初始化,只要放在rand函数之前就行了。
第2个回答 2020-01-18
函数名:
random
功
能:
随机数发生器
用
法:
int
random(int
num);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
#include
<time.h>
/*
prints
a
random
number
in
the
range
0
to
99
*/
int
main(void)
{
randomize();
printf("Random
number
in
the
0-99
range:
%d\n",
random
(100));
return
0;
}
函数名:
randomize
功
能:
初始化随机数发生器
用
法:
void
randomize(void);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
#include
<time.h>
int
main(void)
{
int
i;
randomize();
printf("Ten
random
numbers
from
0
to
99\n\n");
for(i=0;
i<10;
i++)
printf("%d\n",
rand()
%
100);
return
0;
}
函数名:
rand
功
能:
随机数发生器
用
法:
void
rand(void);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
int
main(void)
{
int
i;
printf("Ten
random
numbers
from
0
to
99\n\n");
for(i=0;
i<10;
i++)
printf("%d\n",
rand()
%
100);
return
0;
}
第3个回答 2020-04-25
生成四位随机数,主要用于网页验证码。
<%
dim
num1
dim
rndnum
randomize‘初始化随机数生成器
do
while
len(rndnum)<4'如果rndnum长度小于4就循环
num1=cstr(chr((57-48)*rnd+48))'生成一个随机数
rndnum=rndnum&num1’把随机数连接起来
loop
session("code")=rndnum'把随机数放入session
%>
第4个回答 2019-09-23
函数名:
random
功
能:
随机数发生器
用
法:
int
random(int
num);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
#include
<time.h>
/*
prints
a
random
number
in
the
range
0
to
99
*/
int
main(void)
{
randomize();
printf("Random
number
in
the
0-99
range:
%d\n",
random
(100));
return
0;
}
函数名:
randomize
功
能:
初始化随机数发生器
用
法:
void
randomize(void);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
#include
<time.h>
int
main(void)
{
int
i;
randomize();
printf("Ten
random
numbers
from
0
to
99\n\n");
for(i=0;
i<10;
i++)
printf("%d\n",
rand()
%
100);
return
0;
}
函数名:
rand
功
能:
随机数发生器
用
法:
void
rand(void);
程序例:
#include
<stdlib.h>
#include
<stdio.h>
int
main(void)
{
int
i;
printf("Ten
random
numbers
from
0
to
99\n\n");
for(i=0;
i<10;
i++)
printf("%d\n",
rand()
%
100);
return
0;
}