可能重复:
In C, how do I get a specific range of numbers from rand()?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char** argv) {
srand(time(NULL));
int r = rand();
printf("%d\n", r);
return (EXIT_SUCCESS); }
我有这个代码,我想从1-6创建随机数,并填写一个板[40]任何想法?
答案 0 :(得分:0)
int main(int argc, char** argv) {
int i;
int array[40];
srand(time(NULL));
for (i=0; i<40; i++)
array[i] = rand()%6 + 1
return (EXIT_SUCCESS);
}