I am trying to generate several random numbers from normal distribution using Mathematica. The following is the relevant code:
Clear["Global`*"];
SeedRandom[8396]
Sigma = 1;
Dim = 4;
A = RandomReal[NormalDistribution[0, Sigma], Dim,
WorkingPrecision -> 6];
B = RandomReal[NormalDistribution[0, Sigma], {Dim, Dim, Dim},
WorkingPrecision -> 6];
F = RandomReal[NormalDistribution[0, Sigma], {Dim, Dim, Dim, Dim},
WorkingPrecision -> 6];
Now, when I print out B
, there are several infinities! B
looks as follows:
{{{-1.92981, -1.21226, -0.244472, -0.00362004},
{0.700307, 1.49892, 0.874067, -0.539336},
{-0.643797, 0.356028, \[Infinity], -\[Infinity]},
{-0.130875, -0.379856, 2.20859, 1.65716}},
{{-1.87016, 0.478610, 0.261428, -1.15096},
{-0.0967131, 1.75239, -0.130795, -0.488940},
{-0.771886, 1.04727, -0.499386, 0.180890},
{-0.844033, 0.439520, -0.153382, 0.0686604}},
{{1.75313, -0.917641, -0.222227, 0.746214},
{1.40456, -0.249076, 1.90326, 0.436745},
{1.14792, 0.369685, 0.00756157, 0.407814},
{1.47316, 1.60401, 0.923612, -0.776877}},
{{0.764598, -1.58140, 1.66268, -1.93439},
{-0.520680, 0.227234, 0.908374, -1.11542},
{-2.28119, -1.58329, -0.536070, 0.209272},
{-0.157313, -0.0102335, -0.225685, -0.198312}}}
How is it possible? It shouldn't be because of the WorkingPrecision->6
, is it?!
This happens to specific RandomSeed
, e.g., in this case, 6893. For other RandomSeed
, I don't get this problem!
I want to leave WorkingPrecision->6
as it is to avoid larger floating numbers in the computation, unless it is this specific option that's the problem. Any idea?!
Thanks.
SeedRandom
is intended to be used with42
:) $\endgroup$