# Is there a limit to the SPSS random number generator?

Will the random number generator in SPSS be serviceable if I need 250,000 random numbers, or will the randomness start to degenerate?

Asked another way, what practical limits are there to using the random number generator in SPSS to generate large numbers of random numbers?

I think SPSS, like most modern software, uses the Mersenne Twister. Its period is $2^{19937} − 1$ so you’re pretty safe from this point of view.

Up to 623 successive outcomes are uncorrelated, so you can safely consider a few consecutive outcomes as independent (this would not be the case with a classical Linear congruential generator).

To summarize: modern random number generators are performant enough for all ordinary applications in statistics... don’t worry.

• Thank you for your answer. Let me ask a follow-on question. You say: <Up to 623 successive outcomes are uncorrelated> What size correlation might be seen in numbers past 623? – Joel W. Dec 27 '11 at 0:44
• To be more precise: if you use the full 32 bits numbers it generates, the vectors of length 624 are not equidistributed. So if you use Monte Carlo method to compute $\int_{x \in [0,1]^{624}} f(x) \mathrm d x$ you shouldn’t use Mersenne Twister – at least in theory, in practice for reasonnably shaped $f$ this should be ok, and I don’t think this is the main issue you would run into. If you use only the most significants bits (let’s say the 16 upper bits), I think you can go further but I don’t this precisely. – Elvis Dec 27 '11 at 8:23
• Moreover, if you know 624 successive outputs, you can retrieve the internal state of the generator and predict alol its behaviour, but this is not a true issue for Monte Carlo applications. Finally, if you need uncorrelated vectors in very high dimensions, you may create your own generator in the family of Marsaglia’s Multiplicative With Carry generators, which are easy to deal with. – Elvis Dec 27 '11 at 8:27
• I do not think advising to build one's own generator is a sensible piece of advice. Existing generators have been tested and cross-tested, stick to them! – Xi'an Dec 27 '11 at 9:50
• @Xi'an Marsaglia’s MWC is a very good RNG, it has been extensively tested (Marsaglia is the creator of the so called "Diehard tests" for RNG). It is not difficult to construct high dimensional variants of MWC. However, I think that you are right on one point: if you do so, you should ensure your generator pass the Diehard tests. – Elvis Dec 27 '11 at 12:46

SPSS Statistics provides both the Mersenne Twister and, for compatibility, an older shift-congruential generator. By default, the older generator is used. Use SET RNG=MT or the Transform>Random Number Generators menu item to change this. The MT should give you all the numbers you need.

There is also a user-contributed Python function that fetches truly random, not pseudo random numbers generated from atmospheric noise. These are fetched from a website that has some rules about quantities that you should read. The package is tr_rnd0.1.zip. It can be downloaded from the SPSS Community website in the Python Modules collection. Of course, this requires you to use Python programmability. The tools for that can also be downloaded from the Community site.

I used the SPSS uniform function to create a random sample weekly for two years. Do not do this. They DO NOT generate random samples. The same dataset will generate the same random sample upon re-opening SPSS. Not all cases have the same probability to be selected (depends on sorting of your file).

My recommendation would be to use several methods of randomization sequentially. E.g. first randomize sorting, then use the select random sample function.

• The same dataset will generate the same random sample upon re-opening SPSS. Sure. Because at the start of the session, random seed is one the same. You should first command to set it random before doing random generations of data. – ttnphns Jul 18 '16 at 9:39
• Correct. Also note that similar datasets will generate similar random queries if you don't set the seed to random. – joost schouppe Nov 3 '16 at 12:17