duplicates - How to get an array of random number in Fortran -


the code below generates array of n integer random numbers , stores result in random_int_array

 n=20  allocate(array(n/2))  call random_seed  call random_number(array)  random_int_array=int(array*n) 

the problem might generates duplicates in random_int_array , don't want that. how can remove duplicate array or, equivalently, how can generate set of unique random numbers?

note array has dimension n/2. problem extract n/2 numbers, without duplicates, out of n.

it sounds want integers 1 19 in random order. shuffle of integers. see, e.g., http://tekpool.wordpress.com/2006/10/06/shuffling-shuffle-a-deck-of-cards-knuth-shuffle/ or http://en.wikipedia.org/wiki/fisher-yates_shuffle


Comments