看板 C_and_CPP 關於我們 聯絡資訊
#include <cstdlib> #include <iostream> using namespace std; // ---------------------------------------------- #include <math.h> // ---------------------------------------------- // rnd1( &s1); void rnd1(int *s1) { double x1, x2, x3; x1= (double) (*s1); x2= x1*16807.0; x3= fmod(x2, 2147483647.0); (*s1)= (int) (x3 + 0.5); }// end of rnd1() // ---------------------------------------------- void init_rnd(int *ss) { int s1, s2, ct1; s1= time(NULL); s2= s1; ct1= 0; while (s1 == s2) { // get new s1 s1= time(NULL); ct1++; } // s1 <> s2 *ss= (s1 + ct1); }// end of init_rnd() // ---------------------------------------------- int main(int argc, char *argv[]) { int s1, i; init_rnd(&s1); printf("\n s1= %d \n", s1); for (i=1;i<=20;i++) { rnd1(&s1); printf("s1= %12ld \n", s1); } system("pause"); return EXIT_SUCCESS; }// end of main() -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.193.224.204
bernachom:謝謝幫忙^_^ 05/15 21:08
sjgau:不客氣!針對這個議題,討論的空間 還很大! 05/16 10:08