[UP]


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
6 5 4 10 3 2 1 7 8 9
six five four ten three two one seven eight nine
5 3 1 2 10 7 4 9 6 8
five three
  one two ten seven four nine six eight
10 1 9 5 3 4 2 6 7 8
ten one nine five three four two six seven eight
7 5 1 8 10 2 6 9 3 4
seven five one eight ten two six nine three four
6 8 1 10 9 7 4 5 3 2
six eight
  one ten nine seven four five three two
2 4 8 9 7 3 6 1 10 5
two four eight nine seven three six one ten five
6 5 2 9 8 10 1 7 3 4
six five two nine eight ten one seven three four
5 3 4 9 6 2 10 1 7 8
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.