From 483e783649b0cb8341803ced63c0f72acb4a35db Mon Sep 17 00:00:00 2001 From: kcwu Date: Wed, 5 Oct 2005 19:35:25 +0000 Subject: make the ticket number less preditable. git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3220 63ad8ddf-47c3-0310-b6dd-a9e9d9715204 --- util/openticket.c | 65 ++++++------------------------------------------------- 1 file changed, 7 insertions(+), 58 deletions(-) (limited to 'util') diff --git a/util/openticket.c b/util/openticket.c index f24aaea3..c200510d 100644 --- a/util/openticket.c +++ b/util/openticket.c @@ -56,64 +56,13 @@ int main(int argc, char **argv) fclose(fp); } - srandom(33); // 固定一個 seed 但盡量要避免跟別人的seed同 - - for( n = (now / (60*60*3)) - 62820; n >0; n--) random(); - - -/* - * 正確的random number generator的用法 - * 是用同一個 seed後取 第一個 第二個 地三個.... 數 - * srand() 設完seed後 - * 每呼叫一次rand()就取下一個數 - * - * 但因為我們沒有記錄上次取到第幾個 - * 所以用每增四小時()就多取一次 => now / (60*60*4) (每五小時開一次獎) - * (減 61820 是減少 loop 數) - * - * 本來是用srand(time(0)) 不是正確的用法 - * 因為開獎時間有規率 所以會被找出規律 - * - * ~Ptt - */ - - bet=random() % 8; - /* 以上的說法及 code 並沒比 srand(time(0)) 好. 甚至更好預測. */ - - - //XXX: resolve_utmp(); - attach_SHM(); - bet = SHM->UTMPnumber % 8; - /* FIXME 現在完全依 UTMPnumber 取值, 並沒用到 random function. - * 小站的 UTMPnumber 可視為定值... */ - -/* - - * - * 若要以rand inplement 整數的亂數 要注意以下 (man page中有) - * - * In Numerical Recipes in C: The Art of Scientific Computing - * (William H. Press, Brian P. Flannery, Saul A. Teukolsky, - * William T. Vetterling; New York: Cambridge University - * Press, 1990 (1st ed, p. 207)), the following comments are - * made: - * "If you want to generate a random integer between 1 - * and 10, you should always do it by - * - * j=1+(int) (10.0*rand()/(RAND_MAX+1.0)); - * - * and never by anything resembling - * - * j=1+((int) (1000000.0*rand()) % 10); - * - * (which uses lower-order bits)." - * - * Random-number generation is a complex topic. The Numeri- - * cal Recipes in C book (see reference above) provides an - * excellent discussion of practical random-number generation - * issues in Chapter 7 (Random Numbers). - * ~ Ptt - */ + /* 現在開獎號碼並沒用到 random function. + * 小站的 UTMPnumber 可視為定值, 且 UTMPnumber 預設一秒才更新一次 + * 開站一段時間的開獎 pid 應該無法預測. + * 若是小站當站開獎前開站, 則有被猜中的可能 */ + attach_SHM(); + bet = (SHM->UTMPnumber+getpid()) % 8; + money = ticket[bet] ? total * 95 / ticket[bet] : 9999999; -- cgit v1.2.3