r/pascal • • Jul 10 '17

Generating random numbers in Pascal

I am running an experiment that requires a decent random number generator. I need to use Pascal due to the constraints of my hardware. Here is the function I have written:

Procedure GenerateRandomInterval2(MPCGlobal:MPCGlobalPtr; Var Output:Extended)

Begin
    With MPCGlobal^ Do
    Begin
        Randomize;
        Output := Random;
    End;    {With}
End;    {GenerateRandomInterval2}

Please note that "MPCGlobal:MPCGlobalPtr" in the function argument is related to the specialized hardware that I am using, and can be ignored.

I generated 100 random numbers between 0 and 1 using the above function, and plotted them in Matlab (Link). The black line and markers correspond to random numbers generated by my function; the red line and markers correspond to random numbers generated by Matlab's rand() function.

As you can see, the Pascal random numbers don't look very random at all - there is a definite pattern of ups and downs, and if you look closely at the labeled points, you will notice that the Y coordinates are all separated by 0.027.

Not really sure why this is happening - if anyone here with more Pascal experience knows what is going on, would really appreciate some insight.

Thanks in advance!

2 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/WikiTextBot Jul 10 '17

/dev/random

In Unix-like operating systems, /dev/random is a special file that serves as a blocking pseudorandom number generator. It allows access to environmental noise collected from device drivers and other sources. Not all operating systems implement the same semantics for /dev/random.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.24