一個非常簡單的求隨機數的算法

 #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;
}

<script type=text/javascript> </script><SCRIPT src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type=text/javascript> </SCRIPT>
Google
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章