From 1b46ba9ee6ac7b1a379ac9dcf856d9bfaf09fcff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 1 Oct 2018 20:54:03 +0200 Subject: [PATCH] Make legislation proposals random seed more robust Using a number with only two decimals means the seed is going to be the same 1% of the time. Using ruby's default value for random numbers makes it almost impossible to generate the same seed twice. Using `rand` also simplifies the code, and it's what we use in the budget investments controller. --- app/controllers/legislation/processes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 145a44871..fd301fb07 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -117,7 +117,7 @@ class Legislation::ProcessesController < Legislation::BaseController end def set_random_seed - seed = (params[:random_seed] || session[:random_seed] || (rand(99) / 100.0)).to_f + seed = (params[:random_seed] || session[:random_seed] || rand).to_f seed = (-1..1).cover?(seed) ? seed : 1 session[:random_seed] = seed