lundi 30 novembre 2015

+1/-1 randomly distributed in 2D array

I would like to create a 4x4 array which is filled randomly with +1 or -1 only in fortran95. I found a post that can generate numbers:

program rand_test
use,intrinsic :: ISO_Fortran_env
real  :: r(6)
integer       :: i(6)

! call init_random_seed() would go here

call random_number(r)

i = -1 + FLOOR(3*r)       ! n=-1 and m=1

print *, i
end program

However, this includes 0 which I don't want. Is it possile to remove the 0, if so, how?




Aucun commentaire:

Enregistrer un commentaire