使用随机函数

来源:百度知道 编辑:UC知道 时间:2024/07/08 09:52:15
我想要这样一个代码 不断的产生不重复随机函数 比如1到9 如果是偶数就打出来 如果不是 就产生下一个随机数 这应该怎么写? 请说下 谢谢~~
呃 不好意思 是我没说清楚 我想要的是VB的代码

#include "stdlib.h"
#include "time.h"
void main(){
int n;
time_t t;
while(1){
if (rand()%1000==0) srand((unsigned) time(&t));
n=(int)(rand()%9+1);
if (n%2==0) {
printf("%d",n);
getchar();
}
}
}
按一下出一个随机数

c语言
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main()
{
srand(time(0));
int i;
while(1) {
i=rand()%9+1;
if(i%2==0) printf("%d\n",i);
}
}