[gnome-sudoku/gnome-3-20] qqwing-wrapper: Seed RNG
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/gnome-3-20] qqwing-wrapper: Seed RNG
- Date: Tue, 12 Jul 2016 04:16:41 +0000 (UTC)
commit 30065efc87d381991f51c2a2d39b0ffb0b04425b
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Mon Jul 11 23:15:13 2016 -0500
qqwing-wrapper: Seed RNG
This is ugly. On the master branch, we will use std::once_flag, but for
gnome-3-20 let's avoid adding a dependency on C++ 11.
https://bugzilla.gnome.org/show_bug.cgi?id=768345
lib/qqwing-wrapper.cpp | 11 +++++++++++
1 files changed, 11 insertions(+), 0 deletions(-)
---
diff --git a/lib/qqwing-wrapper.cpp b/lib/qqwing-wrapper.cpp
index f6602b5..d0eb059 100644
--- a/lib/qqwing-wrapper.cpp
+++ b/lib/qqwing-wrapper.cpp
@@ -41,6 +41,17 @@ int* qqwing_generate_puzzle(int difficulty)
const int BOARD_SIZE = 81;
SudokuBoard board;
+ // Seed RNG exactly once.
+ static GMutex mutex;
+ static bool seeded = false;
+ g_mutex_lock(&mutex);
+ if (!seeded)
+ {
+ srand(time(nullptr));
+ seeded = true;
+ }
+ g_mutex_unlock(&mutex);
+
board.setRecordHistory(true);
board.setLogHistory(false);
board.setPrintStyle(SudokuBoard::ONE_LINE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]