Mathematica
Matlab
Maple
A:=ArrayTools:-RandomArray(3,4, distribution = uniform); #just to round to 2 decimal points parse~(sprintf~("%0.2f",A));
|
[[0.93,0.66,0.92,0.80], [0.85,0.96,0.42,0.49], [0.04,0.79,0.14,0.96] ] |
Or
interface(displayprecision=5): A:=ArrayTools:-RandomArray(3,4, distribution = uniform);
\[ \left [ {\begin {array}{cccc} 0.970592781760615697& 0.957506835434297598& 0.0975404049994095246& 0.126986816293506055\\ \noalign {\medskip } 0.157613081677548283& 0.546881519204983846& 0.632359246225409510& 0.905791937075619225\\ \noalign {\medskip } 0.964888535199276531& 0.278498218867048397& 0.913375856139019393& 0.814723686393178936\end {array}} \right ] \]
Fortran
program t5implicit none INTEGER(4) ::i=0,j REAL ::A(3,3),mean,sd,pi,temp CALL RANDOM_SEED(i) CALL RANDOM_NUMBER(A) print *, 'from uniform distribution' do i=LBOUND(A, 1),UBOUND(A, 1) print *,A(i,:) end do !this block below uses the logic as explained in !http://rosettacode.org/wiki/Random_numbers#Fortran ! mean=0.0 sd=1.0 pi = 4.0*ATAN(1.0) ! Now convert to normal distribution DO i = 1, SIZE(A,1)-1, 2 DO j = 1, SIZE(A,2)-1, 2 temp = sd * SQRT(-2.0*LOG(A(i,j))) * COS(2*pi*A(i+1,j+1)) + mean A(i+1,j+1) = sd* SQRT(-2.0*LOG(A(i,j)))*SIN(2*pi*A(i+1,j+1))+mean A(i,j) = temp END DO END DO print *, 'from normal distribution' do i=LBOUND(A, 1),UBOUND(A, 1) print *,A(i,:) end do end program t5
>gfortran -Wall -std=f2008 t5.f90 >./a.out from uniform distribution 0.99755955 0.74792767 7.37542510E-02 0.56682467 0.36739087 5.35517931E-03 0.96591532 0.48063689 0.34708124 from normal distribution -4.70122509E-02 0.74792767 7.37542510E-02 0.56682467 5.17370142E-02 5.35517931E-03 0.96591532 0.48063689 0.34708124
Did not find a build-in support for random numbers from normal distribution, need to look more.