From dbcf8cdee0a92bb6a4757725ee5daaa35d8e2261 Mon Sep 17 00:00:00 2001 From: FAPMon <153521965+FAPMon@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:57:33 +0100 Subject: [PATCH] blocks/sources/uniformrandom: fix seed initialization The initialisation of the random seed has been moved from UniformRandomSource:initialize() to UniformRandomSource:process() in order to fix the problem of math.random() generating the same sequence in all the processes when the math.randomseed() action is done before process forking. Signed-off-by: Vanya A. Sergeev --- radio/blocks/sources/uniformrandom.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/radio/blocks/sources/uniformrandom.lua b/radio/blocks/sources/uniformrandom.lua index e4a04363..4ab78c0f 100644 --- a/radio/blocks/sources/uniformrandom.lua +++ b/radio/blocks/sources/uniformrandom.lua @@ -85,16 +85,15 @@ function UniformRandomSource:get_rate() end function UniformRandomSource:initialize() - if self.seed then - math.randomseed(self.seed) - end - self.out = self.data_type.vector(self.chunk_size) end function UniformRandomSource:process() local out = self.out + -- Only run once in each block instance, as math.randomseed() returns nil + self.seed = self.seed and math.randomseed(self.seed) + for i=0, out.length-1 do out.data[i] = self.generator() end