5.0

5.0 | 2 ratings Rate this file 13 downloads (last 30 days) File Size: 14.27 KB File ID: #13007

Random Number Generator

by ChinSoon Lim

 

14 Nov 2006 (Updated 28 Nov 2006)

No BSD License  

True Random Number Generator

Download Now | Watch this File

File Information
Description

This zip file contains
1) 3 MATLAB functions to generate uniformly distributed random numbers in the interval(0, 1)
-> randCrypt.mexw32, randChaos.mexw32, randQuant.mexw32
2) 3 C++ files that created these MATLAB functions
->randCrypt.cpp, randChaos.cpp, randQuant.cpp
3) 3 function references that describe each of the MATLAB function call
->randCryptFunctionRef.txt, randChaosFunctionRef.txt,randQuantFunctionRef.txt

Before you download
1) Results from these random generating functions have precision up to a fixed numDecimalPlaces. This means that randCrypt returns number in the interval 10^-numDecimalPlaces : 10^-numDecimalPlaces : 1 - 10^-numDecimalPlaces. Increasing the precision of the number generated increases the time taken.

2) These functions are much slower than the rand available in MATLAB. This is the price to pay for generate true random numbers. Please read their function reference for more details on the time taken. Hence, if pseudorandom numbers work for you, you can ignore these programs.

3) randChaos and randQuant require internet connection to retrieve random bytes from http://www.random.org and http://www.fourmilab.ch/hotbits respectively. I would like to thank the authors of these website for providing these random bytes.

Syntax
Y = randXXXXX(numDecimalPlaces, m, n)
Y = randXXXXX(numDecimalPlaces,[m n])
Y = randXXXXX(numDecimalPlaces,m,n,p,...)
Y = randXXXXX(numDecimalPlaces,[m n p ...])
Y = randXXXXX(numDecimalPlaces,size(A))

Description
Y = randXXXXX(numDecimalPlaces, m, n) or Y = randXXXXX(numDecimalPlaces, [m n]) returns an m-by-n matrix of random scalar value drawn from a uniform distribution in the interval (0, 1).

Y = randXXXXX(numDecimalPlaces, m, n, p, ...) or Y = randXXXXX(numDecimalPlaces, [m n p ...]) returns an m-by-n-by-p-by-... array of values as described above.

Y = randXXXXX(numDecimalPlaces, size(A)) returns an array that is the same size as A.

Important Notes
1) numDecimalPlaces should be nonnegative integer. The absolute of the negative input is used instead.

2) The size inputs m, n, p, ... should be nonnegative integers. Negative integers are treated as zero.

Remarks
randXXXXX has been motivated by a need for true random generator and a strong nonrandom pattern in Matlab default random number generator[1].

Please read function references for more credits. Thank you.

Each random number of type double is created as follows. Random bytes are splitted into upper and lower 4 bits. If the upper 4 bits in hexdecimal is less than 10, it is used to create one decimal place. The same applies to the lower 4 bits for the next decimal place. Process is repeated until numDecimalPlaces are created.

Examples
Test Example
x = 0:0.00001:1; tic; t = randXXXXX(8,1,10000000); toc; figure; hist(t,x);

Example 1
R = randXXXXX(8,1,1)
R =
0.2190

Example 2
R = randXXXXX(8,3,4)
R =
0.2190 0.6793 0.5194 0.0535
0.0470 0.9347 0.8310 0.5297
0.6789 0.3835 0.0346 0.0671

References
[1] P. Savicky, "A strong nonrandom pattern in Matlab default random number generator", 16 Sep 2006.Available online at
http://www.cs.cas.cz/~savicky/papers/rand2006.pdf.

[2] M. Howard, "Cryptographically Secure Random Number on Windows without using CryptoAPI", 2005. Available online at http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx.

[3] Microsoft MSDN Library description of CryptGenRandom. Available online at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/seccrypto/security/cryptgenrandom.asp

[4] M. Haahr, "Web interface to true random numbers," http://www.random.org/form.html, 2006.

[5] J. Walker, "Hotbits: Genuine random numbers, generated by radioactive decay," http://www.fourmilab.ch/hotbits, 2006.

MATLAB release MATLAB 7.2 (R2006a)
Zip File Content  
Other Files RANDOM MATLAB/randChaos.cpp,
RANDOM MATLAB/randChaos.mexw32,
RANDOM MATLAB/randChaosFunctionRef.txt,
RANDOM MATLAB/randCrypt.cpp,
RANDOM MATLAB/randCrypt.mexw32,
RANDOM MATLAB/randCryptFunctionRef.txt,
RANDOM MATLAB/randQuant.cpp,
RANDOM MATLAB/randQuant.mexw32,
RANDOM MATLAB/randQuantFunctionRef.txt
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
13 Dec 2006 Salvatore Amoroso

Very good. Take more time but works really. I use it in Simulation of Ballistic Deposition

18 Feb 2007 Vincent Chan

smart idea and it works well!

Please login to add a comment or rating.
Updates
27 Nov 2006

included 2 more versions of random number generator.

27 Nov 2006

Created 2 other versions that also generates random numbers

28 Nov 2006

edited description

Tag Activity for this File
Tag Applied By Date/Time
statistics ChinSoon Lim 22 Oct 2008 08:49:20
probability ChinSoon Lim 22 Oct 2008 08:49:20
random ChinSoon Lim 22 Oct 2008 08:49:20
random number ChinSoon Lim 22 Oct 2008 08:49:20
uniform ChinSoon Lim 22 Oct 2008 08:49:20
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com