Re: random numbers in fortran
- From: Jan Vorbrüggen <jvorbrueggen@xxxxxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 10:10:29 +0100
It doesn't, there will certainly be duplicates. Here's a simple-minded way to get what you want:
function scatter(how_many)
integer :: how_many, scatter(how_many), ii, index
real :: numbers(how_many)
call random_number(numbers)
do ii = 1, how_many
index = minloc(numbers, dim=1)
scatter(ii) = index
numbers(index) = 2.0
end do
end function scatter
What this actually does is to sort the random numbers, and use the index sequence that results as the permutation. This is the usual way to do such
things, although your sort algorithm is O(n^2) instead of O(n ld n) - which
for n=52 will hardly matter.
Jan
.
- References:
- random numbers in fortran
- From: lane straatman
- Re: random numbers in fortran
- From: Thomas Koenig
- Re: random numbers in fortran
- From: Michael Metcalf
- random numbers in fortran
- Prev by Date: Re: How to assign a=b=c=2 in fortran in one statement
- Next by Date: Re: Cray binary format
- Previous by thread: Re: random numbers in fortran
- Next by thread: Re: random numbers in fortran
- Index(es):