66问答网
所有问题
当前搜索:
c随机数函数
C
语言怎样产生一定范围的
随机数
?
答:
min 1 //这个
函数
的意义为:随机生成最小的数为1int main(){int num;srand(time(0));num = rand() % (max - min) + min; // 这里的意义,“%”为模运算printf("
随机数
为:%d\n", num);system("pause"); //这个代码可以让弹出的黑框不会一下就消失return 0;} ...
C
语言如何产生不重复的
随机数
答:
用一个数组装
随机数
,一个数组表示已经记录过的随机数;比如说随机0-8,生成一个随机8位数组且数组内各项不重复;例:intarray[8];intarrayIndex[8]={0,0,0,0,0,0,0,0};intk=0;srand(100);while(k<8){ intq=rand()%8+1;if(arrayIndex[q-1]==1){ continue;} array[k]=q;arr...
怎么控制 C++生成
随机数
的范围
答:
include<stdio.h>#include<stdlib.h>#include<conio.h>#include<windows.h>#include<iostream>#define _CRT_SECURE_NO_WARNINGS#include<math.h>#include<string.h>using namespace std;int main(){int shu,xian;int i;int arr[100001];MAIN:printf("详细说明;此程序将绘制一个
随机数
表并保存至...
c
语言
随机
生成10到加减法题 用rand
函数
?
答:
先用srand
函数
设置
随机数
种子,再用rand函数取两个随机数作为运算数字,而运算符只有+和-,那么用rand()%2来得到0~1的随机数来决定运算符号。下面演示代码,随机生成10道加减题,输入回答,判断正确性。include<stdio.h> include<stdlib.h> include define M 10//题目数量 int main(void){ int n=...
C语言中,主函数中调用一个
随机数函数
,保证每次产生的随机数不重复,该如...
答:
其实只要做一次种,然后再调用rand()就能产生不同的结果了,不用每次调用rand()之前都用srand()做种的 也就是说你那个程序可以改为 srand(time(0));for(a=0; a<200; a++){ /* Two adjacent values of random numbers must be different */ R=rand()/(RAND_MAX+1.0);b=int(R*num) ...
c++中rand()
函数
的范围
答:
rand
函数
不是真正的
随机数
生成器,而srand()会设置供rand()使用的随机数种子。如果你在第一次调用rand()之前没有调用srand(),那么系统会为你自动调用srand()。而使用同种子相同的数调用 rand()会导致相同的随机数序列被生成。C语言 srand((unsigned)time(NULL))则使用系统定时/计数器的值作为随机...
c语言 调用
随机函数
产生的0到19之间的
随机数
答:
int main(int argc, char *argv[]){ int x;srand(time(NULL));int a[15];int i = 0;for(i=0; i<15; ++i){ //初始化为-1 因为要是初始化为0的话 可能有0这个值 a[i] = -1;}/*---end of for---*/ for( i=0; i<15; ++i){ //生成15个
随机数
x = rand()%20...
c
语言生成1 - 100的不重复
随机数
答:
include<stdio.h>#include#include<stdlib.h>int Rand(int X,int Y)//生成
随机数
{int temp;if(X>Y){temp=X;X=Y;Y=temp;}return rand()%(Y-X+1)+X; }void main(){int arr[100];int i;int r;int temp;srand((unsigned)time(NULL));for(i=0;i<100;i++) arr[i]=i+1;//...
C
语言 srand()
函数
答:
直接用rand() 产生的一套
随机数
是固定不变的。也就是说 这次 产生了 一套 例如有 10 个数 a[0],a[1],..a[9]下次 再跑这个程序 产生 一套 10 个数 b[0],b[1],..b[9]得到的 b[0]==a[0]; b[1]==a[1];...b[9]==a[9];用 srand() 生成新种子,那么 新的...
C
语言产生1~6的一个
随机数
!!急!
答:
代码如下:include <stdio.h> include <stdlib.h> include int main(){ int x,num;srand(time( NULL ));x =1 + (rand()%6);printf("%d",x);return 0;} 源代码截图:参考资料:百度百科-网页链接
棣栭〉
<涓婁竴椤
5
6
7
8
10
11
12
9
13
14
涓嬩竴椤
灏鹃〉
其他人还搜