Skip to content

Initial numbers generated by Util/random.sml have unexpected regularities #256

Description

@MortenRhiger

Version

110.99.2

Operating System

  • Any
  • Linux
  • macOS
  • Windows
  • Other Unix

OS Version

No response

Processor

  • Any
  • Arm (using Rosetta)
  • PowerPC
  • Sparc
  • x86 (32-bit)
  • x86-64 (64-bit)
  • Other

System Component

SML/NJ Library

Severity

Minor

Description

The first ca. 1100 numbers (and perhaps more) produced by Random.randInt display unexpected (to me) regularities (see the charts below). The same regularities show up for the few seeds I tried.

Transcript

The numbers produced look almost like a sine wave scaled by the count. The same regularities show up for the few seeds I tried.

Here are the first 1100 numbers (seed (0, 1)):
random1

And here are the first 300:
random2

Expected Behavior

I am aware that a random sequence must contain long streaks of only positives and long streaks of only negatives (and even display sinusoidal behavior from time to time), but I didn't expect to find them so early in the sequence produced by a random-number generator.

If this is a known and desired symptom of the SWB algorithm, then the solution might be to describe it in the documentation.

Steps to Reproduce

val seed = Random.rand(0,1);
fun loop n = if n > 0 then
               ( print (Format.format "%d\n" [Format.INT (Random.randInt seed)]);
                 loop (n - 1) )
             else ();

Running loop 1200 writes the 1200 numbers plotted above.

Additional Information

No response

Email address

morten.rhiger@gmail.com

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixed-in-110.99.4issues that will be fixed in the 110.99.4 versionsmlnj-libGeneral issue with the SML/NJ Library or the Util component

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions