From: Walter Roberson on
Randima Hettiarachchi wrote:

> I'm doing a research, which requires to seed the pseudo random number
> generator with a 128 bit binary string (eg. 11001101) and obtain a
> vector of 1000 random numbers.

You will have to implement your own random number generator, as that is
not possible in Matlab.

Matlab does not provide any random stream which can be initialized with
128 bits. Matlab random number generators can be initialized with a 32
bit positive integer, or they can be initialized with an exact copy of
their internal state, where their internal state is a cell array which
varies with the generator but often has components that are more than
300 uint32.


> From what I have gathered, we can set the seed either as a scalar or as
> a N length vector.

If that was true once, it is no longer true, not in Matlab 2008a
onwards. Are you perhaps using an older Matlab?

> Still I can set the seed to 128 bits binary string. However, it gives me
> the same output for totally different 128 bits seeds.
> eg.
> Test 1:
> k=10100101111110001010010100000110110100110100111011101010000111010001110110110110111010101100001111001001011111101111001110011000;

After that, k would not be a binary bit stream: it would be a 64 bit
double precision number in the range 1.01001 * 10^128. There is no way
in Matlab to create a 128 bit integer data type (other than using the
Fixed Point Toolbox, but those datatypes are not known to the random
number generator.)


> randn('state', k);

'state' indicates the older "subtract with borrow" random number generator.

You should be transitioning to using RandStream.create rather than using
randn('state',k)
From: Peter Perkins on
Randima, the generators in MATLAB accept an integer value between 0 and
2^31 as a seed, or they accept a state vector that has previously been
read from the generator. You cannot expect to take an arbitrary 128
bits and use that as a state vector (and as Walter pointed out, you
weren't doing that anyway).

It appears as if you want, in effect, to use a 128bit value as a seed.
Perhaps if you explained your requirement for that, it would help.


On 6/6/2010 10:00 AM, Randima Hettiarachchi wrote:
> Hi All,
>
> I'm doing a research, which requires to seed the pseudo random number
> generator with a 128 bit binary string (eg. 11001101) and obtain a
> vector of 1000 random numbers.
>
> From what I have gathered, we can set the seed either as a scalar or as
> a N length vector. I'm successful in setting the seed as a scalar, but
> the challenge that I'm facing is that it only accepts scalars of 10
> bits, but my binary string is 128 bits long.
> Still I can set the seed to 128 bits binary string. However, it gives me
> the same output for totally different 128 bits seeds.
> eg.
> Test 1:
> k=10100101111110001010010100000110110100110100111011101010000111010001110110110110111010101100001111001001011111101111001110011000;
>
> randn('state', k);
> w=randn(1,10); disp(w);
>
> Test 2:
> k=10010100101010101100011001000000100101101000011010001110011001111001111001011101011111010011010100010011010110011000101001010010;
>
> randn('state', k);
> w=randn(1,10); disp(w);
>
> Both Test 1 and Test 2 return the same result:
>
> Columns 1 through 9
>
> 0.7953 0.0222 0.9484 0.6454 -0.6079 1.6226 -0.6279 0.3315 0.0232
>
> Column 10
>
> -0.6825
>
> Greatly appreciate if someone can help me with the problem I'm facing.
>
> Thanks in advance....

From: Walter Roberson on
Peter Perkins wrote:
> Randima, the generators in MATLAB accept an integer value between 0 and
> 2^31 as a seed

Not 2^31:

The limits on seed can be tricky to find in the documentation -- they
are not documented in @RandStream or rand() or Legacy Mode :: Random
Numbers ( techdoc/math/brt5wsv.html ), but they are documented in
RandStream (without the @) and in RandStream.create.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.randstream.html

Seed Nonnegative scalar integer with which to initialize all streams.
Default is 0. Seed must be an integer less than 2^32


http://www.mathworks.com/access/helpdesk/help/techdoc/ref/randstream.create.html

Seed Nonnegative scalar integer with which to initialize all streams.
Default is 0. Seeds must be an integer between 0 and 2^32.


That last documentation is not clear on the meaning of "between"; the
naive reading would suggest that 0 and 2^32 exactly are valid inputs,
but 2^32 exactly is excluded by the first document, which implicitly
allows 0 (especially as 0 is the default.)

I would recommend the documentation be touched up with respect to the
limits.