# [Numpy-discussion] Random Numbers

Karthikesh Raju karthik at james.hut.fi
Wed Jun 2 08:05:09 CDT 2004

```Hi Perry,

Yes, i have been trying to compare random number generators. i plotted the
histograms, they look quite "gaussian", i have also tried uniform numbers
with "rand". May be there is some problem with one of my statements like:

def AWGN(Tx_Symbols,No):
len_Waveform = len(Tx_Waveform)
std_No = sqrt(No/2.0)
return Tx_Waveform + std_No*randn(len_Waveform)

This function just takes in a bit stream in [1,-1] and adds gaussian
noise. No defines the noise power.

Now in the main function i am doing:

Tx_Bit_Stream = random(n_Bits) > 0.5
Tx_Symbols = 2*Tx_Bit_Stream-1
Rx_Symbols = AWGN(Tx_Symbols, No)
Rx_Bit_Stream = Rx_Symbols > 0

n_Errors = sum(not_equal(Tx_Bit_Stream,Rx_Bit_Stream))

Now i have noted that n_Errors is negative? How can that be so?

n_Errors should be the number of places where Tx_Bit_Stream differs from
Rx_Bit_Stream? How can the sum be negative?

With warm regards

karthik

-----------------------------------------------------------------------
Karthikesh Raju,		    email: karthik at james.hut.fi
Researcher,			    http://www.cis.hut.fi/karthik
Helsinki University of Technology,  Tel: +358-9-451 5389
Laboratory of Comp. & Info. Sc.,    Fax: +358-9-451 3277
Department of Computer Sc.,
P.O Box 5400, FIN 02015 HUT,
Espoo, FINLAND
-----------------------------------------------------------------------

On Wed, 2 Jun 2004, Perry Greenfield wrote:

> Karthikesh Raju wrote:
>
> > How close is the random number generation from
> > numarray.random_array.normal(0,1,x) or
> > numarray.linear_algebra.mlab.randn(x) to matlab's randn?
> >
> > i am having problems with an identical program written in matlab and
> > python, with the results entirely different in both cases :(
> >
> Unfortunately, I'm not familiar with matlab and don't have it here
> to run. Have you tried comparing simple things between the two
> such as mean and standard deviation to see if you are getting
> the same result, followed by histograms if you see no differences
> there?
>
> Perry Greenfield
>
>

```