[gnome-sudoku/gnome-3-18] qqwing-wrapper: Seed RNG
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/gnome-3-18] qqwing-wrapper: Seed RNG
- Date: Sat, 30 Jul 2016 15:33:27 +0000 (UTC)
commit 95b99df63e1704cca55b13ba27f140bf4961fabb
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 99c4562..dfd0ac4 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(NULL));
+ 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]