Re: random numbers in fortran




"lane straatman" <grumpy196884@xxxxxxxxxxx> wrote in message
news:1164653494.820050.94760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Since I want to simulate shuffling a deck of cards, I guess I'll ask
for 52 pseudorandoms at a pop, multiply by 52 and take the floor. I
believe this gives random ints between zero and fifty-one.

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

Regards,

Mike Metcalf


.