From: Jim Weirich Date: 2003-07-30T12:46:24+09:00 Subject: OT: Random Number Story (Was: Generating random numbers?) On Tue, 2003-07-29 at 15:40, Yukihiro Matsumoto wrote: > You don't need to call srand unless you want to reproduce random > number sequence. This reminds me of a off-topic story involving srand(). Unfortunately it has nothing to do with Ruby. I was teaching an after hours C++ class at work. Part of the class assignment was to write a Dice playing game. Students were to provide a Player object that participated in a game framework. Being a C++ class, I was stressing the difference between public and private and how the framework prevented players from causually interfering with each other and "cheating" in the game. Of course, merely stressing this issue is enough motivation for some to start looking for loopholes. One student discovered an interesting "cheat". His player object created a local copy of a dice object (he didn't have access to the actual Dice used by the framework). He then rolled until he got a good score from his local dice. Before each roll, he would record the value of the random seed. Just before he asked the framework to roll the *real* dice object, he used srand to set the seed that gave him a good score. -- -- Jim Weirich jweirich@one.net http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)