Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Random numbers, binary files and randomness tests

Subject: Random numbers, binary files and randomness tests

From: Rudina zeqirllari

Date: 6 May, 2009 16:39:02

Message: 1 of 5

Hi
i am a student and i'm working with matlab, in order to create my own rng. I have written a program in matlab and it produces numbers between 0 and 1. now i should test them(if are random). my numbers have a beta distribution with shape parameters a=b= 0.5. (I have seen the histograms and i have used betafit in order to find a and b). i have test these numbers only with runstest. now i have some questions:
1) is this test a randomness test and it is used for numbers with a beta distribution?
2) There are other randomness tests in matlab(for numbers with a beta distribution)?
3) if no, how can i convert this distribution (beta) in a unifom one,in order to test them with other randomness test?
4) if i test these numbers with NIST, Diehard, etc, they should have a binary format (32 bit). how can i specified this thing when i save the data? (i thought that was enough to save them in a mat file format, but perhaps it's not).
thank you

Subject: Random numbers, binary files and randomness tests

From: Peter Perkins

Date: 7 May, 2009 13:34:43

Message: 2 of 5

Rudina zeqirllari wrote:

> i am a student and i'm working with matlab, in order to create my own rng. I have written a program in matlab and it produces numbers between 0 and 1. now i should test them(if are random). my numbers have a beta distribution with shape parameters a=b= 0.5. (I have seen the histograms and i have used betafit in order to find a and b). i have test these numbers only with runstest. now i have some questions:
> 1) is this test a randomness test and it is used for numbers with a beta distribution?
> 2) There are other randomness tests in matlab(for numbers with a beta distribution)?
> 3) if no, how can i convert this distribution (beta) in a unifom one,in order to test them with other randomness test?

Rudina, I assume what you mean is that your generator was designed to produce values from a Beta(.5,.5) distribution, and you are trying to check that assumption. One thing you can do is to use a one-sample K-S test on a large number of samples of size, say, 1000. The p-values across a large number of independent samples ought to be uniformly distributed, since the null hypothesis is true.

To transform to a uniform distribution, use the inverse CDF for your distribution. For example,

   b = betarnd(.5,.5,1000,1);
   u = betainv(b,.5,.5);

There is a large amount of research and literature on testing random number generators. I recommend looking at some of the papers and software by Pierre L'Ecuyer, e.g.,

<http://www.iro.umontreal.ca/~simardr/testu01/tu01.html>

for ideas on what tests you might want to try. Most of them should be pretty easy to implement in M.

Hope this helps.

Subject: Random numbers, binary files and randomness tests

From: Rudina zeqirllari

Date: 7 May, 2009 15:03:25

Message: 3 of 5

Mr Perkins
Thank you for the response. i have tried before what you suggest me for converting a beta distribution in a uniform one, but if you see the histograms of u (utainv(b,0.5,0.5)), they don't appear uniform. this is the only way matlab has for convert them? i have another question also about binary format(32 bit)and mat file format. so, if i save the data, they are saved in a mat file format. usually randomness tests work with binary files(32 bit)[i don't know if this is always true]. so, my question is: how can i save the data in 32 bit binary file?
thank you again

Subject: Random numbers, binary files and randomness tests

From: Peter Perkins

Date: 7 May, 2009 22:07:56

Message: 4 of 5

Rudina zeqirllari wrote:

> Thank you for the response. i have tried before what you suggest me for converting a beta distribution in a uniform one, but if you see the histograms of u (utainv(b,0.5,0.5)), they don't appear uniform. this is the only way matlab has for convert them?

This is nothing to do with MATLAB, it is standard probability theory. If utainv(b,0.5,0.5)) applied to a vector b of values from your generator does not result in something approximately uniform, then your generator must not be creating values from a Beta(.5,.5) dist'n.

Subject: Random numbers, binary files and randomness tests

From: Rudina zeqirllari

Date: 2 Jun, 2009 17:45:17

Message: 5 of 5

I found a way to transform a beta distibution with a=b=0.5, in a uniform one. i just used the cdf of each value of the beta distr. so i used betacdf(x,a,b), where x is the vector with beta distribution data, and i got a uniform distribution. now i want to know how can i save these data in a 32 bit file? usually matlab save data in mat file(so binary file in double precision). can someone help me?
thank you

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us