diff options
author | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-10-06 03:35:25 +0800 |
---|---|---|
committer | kcwu <kcwu@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2005-10-06 03:35:25 +0800 |
commit | 483e783649b0cb8341803ced63c0f72acb4a35db (patch) | |
tree | 8070bd190c785b8ec2973a96c3bcfc429496e68c /util | |
parent | b3bdc0360ad8d86422e84055c32cfee26d04db9f (diff) | |
download | pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar.gz pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar.bz2 pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar.lz pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar.xz pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.tar.zst pttbbs-483e783649b0cb8341803ced63c0f72acb4a35db.zip |
make the ticket number less preditable.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3220 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util')
-rw-r--r-- | util/openticket.c | 65 |
1 files changed, 7 insertions, 58 deletions
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; |