Manual Reference Pages - random_permutation (3)
NAME
random_permutation(3f) - [M_random] Populate an integer array with the values 1 to size(array)
CONTENTS
Synopsis
Description
Options
Example
SYNOPSIS
subroutine random_permutation( array )
integer,intent(inout) :: array(:)
DESCRIPTION
Populate the given integer array with the numbers 1 to size(array) arranged in
random order.
OPTIONS
array |
Integer array that will be filled with integers 1 to N in
random order
|
|
EXAMPLE
Sample program
program demo_random_permutation
use M_random, only : random_permutation
implicit none
integer :: array(10)
character(len=*),parameter :: list(*)=[character(len=5) :: &
& one,two,three,four,five,six,seven,eight,nine,ten]
integer :: i, j
do i = 1,8
call random_permutation(array)
write(*,(*(i5,1x))) array
! use random values as indices to randomize another array
write(*,(*(a,1x))) (adjustr(list(array(j))),j=1,size(array))
enddo
end program demo_random_permutation
Example output
six |
five four ten three two one seven eight nine
|
five three |
|
one two ten seven four nine six eight
|
ten |
one nine five three four two six seven eight
|
seven |
five one eight ten two six nine three four
|
six eight |
|
one ten nine seven four five three two
|
two |
four eight nine seven three six one ten five
|
six |
five two nine eight ten one seven three four
|
five three |
|
four nine six two ten one seven eight
|
|
| random_permutation (3) | September 06, 2019 |
Generated by manServer 1.08 from 0d3b2aeb-760d-469e-ad7f-bc77719803c5 using man macros.