Subject: bug#78375: closed (Re: [bug#78375] daemon: Replace random_shuffle() with shuffle(), [PATCH] Replace random_shuffle with shuffle)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 12 May 2025 08:55:07 +0000

Your bug report

#78375: daemon: Replace random_shuffle() with shuffle()

which was filed against the guix-patches package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78375: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78375
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: [bug#78375] daemon: Replace random_shuffle() with shuffle(), [PATCH] Replace random_shuffle with shuffle
From: Ludovic Courtès <[email-masked]>
To: Congcong Kuo <[email-masked]>
Cc: [email-masked]
Date: Mon, 12 May 2025 10:11:42 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

Congcong Kuo <[email-masked]> writes:

> I am trying to build libstore using the Zig build system. The default
> C++ version of ‘zig c++’ is gnu++17 and random_shuffle() has been
> removed in C++ 14 standard.
>
> Even though guix is built using gnu++11 currently, I think it is not harmful to replace a deprecated function.
>
> Regards,
> Kuo
>
> From fc7ccca0a1a58e16d1c4729b31bc477deddb308b Mon Sep 17 00:00:00 2001
> From: Congcong Kuo <[email-masked]>
> Date: Sun, 11 May 2025 16:31:22 +0800
> Subject: [PATCH] Replace random_shuffle with shuffle
>
> ---
>  nix/libstore/gc.cc | 5 ++++-

I added a commit log following our conventions and applied it, thanks!

Ludo’.

Subject: daemon: Replace random_shuffle() with shuffle()
From: Congcong Kuo <[email-masked]>
To: [email-masked]
Date: Sun, 11 May 2025 17:24:02 +0800
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

I am trying to build libstore using the Zig build system. The default C++ version of ‘zig c++’ is gnu++17 and random_shuffle() has been removed in C++ 14 standard.

Even though guix is built using gnu++11 currently, I think it is not harmful to replace a deprecated function.

Regards,
Kuo

From fc7ccca0a1a58e16d1c4729b31bc477deddb308b Mon Sep 17 00:00:00 2001
From: Congcong Kuo <[email-masked]>
Date: Sun, 11 May 2025 16:31:22 +0800
Subject: [PATCH] Replace random_shuffle with shuffle

---
 nix/libstore/gc.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/nix/libstore/gc.cc b/nix/libstore/gc.cc
index 1651911..261ea79 100644
--- a/nix/libstore/gc.cc
+++ b/nix/libstore/gc.cc
@@ -4,6 +4,7 @@
 
 #include <functional>
 #include <queue>
+#include <random>
 #include <algorithm>
 
 #include <sys/types.h>
@@ -745,7 +746,9 @@ void LocalStore::collectGarbage(const GCOptions & options, GCResults & results)
                alphabetically first (e.g. /nix/store/000...).  This
                matters when using --max-freed etc. */
             vector<Path> entries_(entries.begin(), entries.end());
-            random_shuffle(entries_.begin(), entries_.end());
+            std::random_device seeder;
+            std::default_random_engine generator(seeder());
+            std::shuffle(entries_.begin(), entries_.end(), generator);
 
             foreach (vector<Path>::iterator, i, entries_)
                 tryToDelete(state, *i);
-- 
2.45.2