View Issue Details

IDProjectCategoryView StatusLast Update
0029526FPCRTLpublic2016-01-28 13:09
ReporterOndrej Pokorny Assigned ToJonas Maebe  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
Summary0029526: Patch: add Randomize with randseed parameter
DescriptionFor some usages the default randomize procedure (randseed:=GetTickCount) is not good enough.
(E.g. in multithreading when randomize can return the same randseed for parallel threads.)

Please allow to set the randseed manually.
Additional InformationPatch attached.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Ondrej Pokorny

2016-01-28 12:50

developer  

randomize-ARandseed.patch (704 bytes)   
Index: rtl/inc/systemh.inc
===================================================================
--- rtl/inc/systemh.inc	(revision 33002)
+++ rtl/inc/systemh.inc	(working copy)
@@ -840,6 +840,7 @@
 Function  Random: extended;
 {$endif}
 Procedure Randomize;
+Procedure Randomize(ARandseed:cardinal);
 {$endif FPC_HAS_FEATURE_RANDOM}
 
 {$ifdef FPC_HAS_INTERNAL_ABS_LONG}
Index: rtl/win/syswin.inc
===================================================================
--- rtl/win/syswin.inc	(revision 33002)
+++ rtl/win/syswin.inc	(working copy)
@@ -349,6 +349,10 @@
     randseed:=GetTickCount;
   end;
 
+  procedure Randomize(ARandseed:cardinal);
+  begin
+    randseed:=ARandseed;
+  end;
 
 
 
randomize-ARandseed.patch (704 bytes)   

Jonas Maebe

2016-01-28 12:58

manager   ~0089466

Randseed is a global variable that you can change directly.

Ondrej Pokorny

2016-01-28 13:03

developer   ~0089468

Stupid me. Thanks.

Jonas Maebe

2016-01-28 13:09

manager   ~0089470

Also: the entire state of the random number generator consists of regular global variables, so it is not safe to use it from multiple threads in parallel.

Issue History

Date Modified Username Field Change
2016-01-28 12:50 Ondrej Pokorny New Issue
2016-01-28 12:50 Ondrej Pokorny File Added: randomize-ARandseed.patch
2016-01-28 12:58 Jonas Maebe Note Added: 0089466
2016-01-28 12:58 Jonas Maebe Status new => resolved
2016-01-28 12:58 Jonas Maebe Resolution open => no change required
2016-01-28 12:58 Jonas Maebe Assigned To => Jonas Maebe
2016-01-28 13:03 Ondrej Pokorny Note Added: 0089468
2016-01-28 13:03 Ondrej Pokorny Status resolved => closed
2016-01-28 13:09 Jonas Maebe Note Added: 0089470