Posted on 2007-04-01 15:54
kk 閱讀(564)
評論(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();