// filename:c2011-7-22-2-2-ex.c // original examples and/or notes: // (c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011 // C2011 7.22.2.2 The srand function // compile and output mechanism: // (c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.29, 2013 // compile errors and/or wornings: // 1 (c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn) // Target: x86_64-apple-darwin11.4.2 //Thread model: posix // (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign. // 2 gcc-4.9 (GCC) 4.9.0 20131229 (experimental) // Copyright (C) 2013 Free Software Foundation, Inc. #include // Example static unsigned long int next = 1; int rand(void) // RAND_MAX assumed to be 32767 { next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768; } void srand(unsigned int seed) { next = seed; } int main(void) { int i; srand(i); i= rand(); return printf("7.22.2.2 The srand function %d\n",i); } // output1(LLVM) may be // 7.22.2.2 The srand function 188 // output2(GCC4.9) may be // 7.22.2.2 The srand function 25968 //乱数なので、コンパイルの度に最後の結果は同じではないはず。 //LLVMだと毎回値が違う。gcc4.9だと値が同じ。原因不明。