From: Jerome St-Louis Date: Thu, 7 Aug 2014 07:44:48 +0000 (-0400) Subject: samples; coursework: Fixed random seeding with time not working X-Git-Tag: 0.44.10~9 X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?p=sdk;a=commitdiff_plain;h=46317d80156bca68c6986c01123c144a77253da8 samples; coursework: Fixed random seeding with time not working - double value would overflow DWORD range on long Windows uptime, and always on Unix as GetTime() returns time since the epoch --- diff --git a/installer/coursework/Chapter 6 - Classes, Methods and Instances/Lab6/lab6.ec b/installer/coursework/Chapter 6 - Classes, Methods and Instances/Lab6/lab6.ec index 268655a..9002aa6 100644 --- a/installer/coursework/Chapter 6 - Classes, Methods and Instances/Lab6/lab6.ec +++ b/installer/coursework/Chapter 6 - Classes, Methods and Instances/Lab6/lab6.ec @@ -576,7 +576,7 @@ class RPGApp : Application void Main() { - RandomSeed((uint)(GetTime()*1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); PrintLn("Welcome to this great minimalist RPG!"); PrintLn("You will need to save the princess from an Evil Sorcerer."); PrintLn("But first you should wander the realm to fight the sorcerer's minions, "); diff --git a/samples/db/MedDB/med.ec b/samples/db/MedDB/med.ec index ca9741a..3e38291 100644 --- a/samples/db/MedDB/med.ec +++ b/samples/db/MedDB/med.ec @@ -154,7 +154,7 @@ class MyApp : GuiApplication { MyApp() { - RandomSeed((uint)(GetTime() * 1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); SetDefaultIdField("id"); SetDefaultNameField("name"); ds = DataSource { driver = "EDB" }; diff --git a/samples/eC/neural/neural.ec b/samples/eC/neural/neural.ec index 094d460..4651023 100644 --- a/samples/eC/neural/neural.ec +++ b/samples/eC/neural/neural.ec @@ -83,7 +83,7 @@ class NeuralApp : Application int i,h,o; int c; - RandomSeed((int)(GetTime() * 1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); // Input to hidden cells synapses for(i = 0; iboard, chessState->turn); int depth = MAXDEPTH; - RandomSeed((int)(GetTime() * 1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); aiMoveResult = FindMove(chessState, 0, &depth, &aiMove, startRating, null, 0, null, &abortAI); return 0; diff --git a/samples/games/chess/src/chess.ec b/samples/games/chess/src/chess.ec index 63383a8..19bc3f1 100644 --- a/samples/games/chess/src/chess.ec +++ b/samples/games/chess/src/chess.ec @@ -149,7 +149,7 @@ class Chess : Window EnableMenus(); - RandomSeed((int)(GetTime() * 10000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); NewGame(); } diff --git a/samples/games/crosswords/CrossWordsServer.ec b/samples/games/crosswords/CrossWordsServer.ec index b359ae7..253f611 100644 --- a/samples/games/crosswords/CrossWordsServer.ec +++ b/samples/games/crosswords/CrossWordsServer.ec @@ -1,6 +1,6 @@ import "crossWords" -int seed; +uint seed; // FOR COMMUNICATION ////////////////////////////////////////// struct PlayedTile @@ -185,7 +185,7 @@ class CrossWordsGame lettersAvailable[l] = lettersCount[language][l]; } - seed = (uint)(GetTime() * 1000); + seed = (uint)(((uint64)(GetTime() * 1000)) & MAXDWORD); //seed = 256131322; RandomSeed(seed); //Logf("Seeded with %d\n", seed); diff --git a/samples/games/tetrominoes/tetrominoes.ec b/samples/games/tetrominoes/tetrominoes.ec index b06b5e7..d0b937a 100644 --- a/samples/games/tetrominoes/tetrominoes.ec +++ b/samples/games/tetrominoes/tetrominoes.ec @@ -263,7 +263,7 @@ class Tetrominoes : Window board[y][x] = 0; turn = CLIENT; Update(null); - RandomSeed((uint)(GetTime() * 1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); nextPiece = GetRandom(0, 6); nextAngle = GetRandom(0, 3); NewPiece(); diff --git a/samples/games/ticTacToe/TicTacToe.ec b/samples/games/ticTacToe/TicTacToe.ec index 36ce40c..9a311cb 100644 --- a/samples/games/ticTacToe/TicTacToe.ec +++ b/samples/games/ticTacToe/TicTacToe.ec @@ -23,7 +23,7 @@ class TicTacToe : Window TicTacToe() { - RandomSeed((uint)(GetTime() * 1000)); + RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); } TTTSquare FindTicTacToe(TTTSquare state[3][3]) diff --git a/samples/guiAndGfx/snow/snow.ec b/samples/guiAndGfx/snow/snow.ec index 8b217e0..9e01c11 100644 --- a/samples/guiAndGfx/snow/snow.ec +++ b/samples/guiAndGfx/snow/snow.ec @@ -30,7 +30,7 @@ class Snowing : Window int lastLine; Bitmap buffer { }; - Snowing() { RandomSeed((uint)(GetTime() * 100000)); ((GuiApplication)__thisModule).timerResolution = 60; } + Snowing() { RandomSeed((uint)(((uint64)(GetTime() * 1000)) & MAXDWORD)); ((GuiApplication)__thisModule).timerResolution = 60; } Timer timer {