Posted on 2007-04-01 15:54
kk 阅读(534)
评论(0) 编辑 收藏 引用 所属分类:
Algorithm
#include <stdio.h>
#include <windows.h>
unsigned long int next = 1;
unsigned int rand(void)
{
next = next * 1103515245 + 12345;
return (unsigned int)(next/65536) % 32768;
}
void srand(unsigned int seed)
{
next = seed;
}
int main()
{
srand(GetTickCount());
for(int i=0; i<10; i++)
{
for(int j=0; j<10; j++)
printf("%d ", rand());
printf("\n");
}
return 0;
}
也可如下:
随机数
#include <stdlib.h>
Srand( GetTickCount() );
Rand();