ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_arrayShuffle::setShuffled Interface Reference

Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle. More...

Detailed Description

Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle.

Parameters
[in,out]rng: The input/output scalar that can be an object of,
  1. type rngf_type, implying the use of intrinsic Fortran uniform RNG.
  2. type xoshiro256ssw_type, implying the use of xoshiro256** uniform RNG.
(optional, default = rngf_type, implying the use of the intrinsic Fortran URNG.)
[in,out]array: The input/output contiguous array of shape (:) of either
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
  2. type logical of kind any supported by the processor (e.g., LK),
  3. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
  4. type complex of kind any supported by the processor (e.g., CK, CK32, CK64, or CK128),
  5. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
or,
  1. a scalar assumed-length character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU),
whose first (1:count) elements will be shuffled uniformly-randomly on return.
The rest of the elements of array(count + 1:) will be shuffled but non-uniformly.
[in]count: The input positive scalar integer of default kind IK, containing the number of elements of the unique uniformly-random draws (shuffled elements) from the input array.
If specified, only the first count elements of the input/output sequence array are guaranteed to be randomly uniformly shuffled.
The specified count must not be larger than the length of the input sequence array.
(optional, default = len(array) for scalar character input array, otherwise size(array).)


Possible calling interfaces

call setShuffled(array, count = count)
call setShuffled(rng, array, count = count)
Perform an unbiased random shuffling of the input array, known as the Knuth or Fisher-Yates shuffle.
This module contains procedures and generic interfaces for shuffling arrays of various types.
Warning
The condition 0 <= count must hold for the corresponding input arguments.
The condition count <= lenArray must hold for the corresponding input arguments where lenArray represents the length of the input sequence.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure. The procedures of this generic interface become pure in release build mode when the input argument rng is set to an object of type xoshiro256ssw_type.
See also
getChoice
setChoice
getRemapped
setRemapped
getReversed
setReversed


Example usage

1program example
2
3 use pm_kind, only: LK ! All kinds are supported.
4 use pm_kind, only: SK ! All kinds are supported.
5 use pm_kind, only: IK ! All kinds are supported.
6 use pm_kind, only: CK ! All kinds are supported.
7 use pm_kind, only: RK ! All kinds are supported.
8 use pm_io, only: display_type
9 use pm_distUnif, only: getUnifRand
11
12 implicit none
13
14 integer(IK) :: count, itry, ntry = 10
15 type(display_type) :: disp
16 disp = display_type(file = "main.out.F90")
17
18 block
19 character(:), allocatable :: array
20 do itry = 1, ntry
21
22 call disp%skip
23 call disp%show("count = getUnifRand(4, 10)")
24 count = getUnifRand(4, 10)
25 call disp%show("array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.")
26 array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
27 call disp%show("array")
28 call disp%show( array, deliml = SK_"""" )
29 call disp%show("call setShuffled(array)")
30 call setShuffled(array)
31 call disp%show("array")
32 call disp%show( array, deliml = SK_"""" )
33
34 call disp%skip
35 call disp%show("count = getUnifRand(0, len(array))")
36 count = getUnifRand(0, len(array))
37 call disp%show("count")
38 call disp%show( count )
39 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
40 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
41 call disp%show("array")
42 call disp%show( array, deliml = SK_"""" )
43
44 end do
45 end block
46
47 block
48 character(2), allocatable :: array(:)
49 do itry = 1, ntry
50
51 call disp%skip
52 call disp%show("count = getUnifRand(4, 10)")
53 count = getUnifRand(4, 10)
54 call disp%show("array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.")
55 array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
56 call disp%show("array")
57 call disp%show( array, deliml = SK_"""" )
58 call disp%show("call setShuffled(array)")
59 call setShuffled(array)
60 call disp%show("array")
61 call disp%show( array, deliml = SK_"""" )
62
63 call disp%skip
64 call disp%show("count = getUnifRand(0, size(array))")
65 count = getUnifRand(0, size(array))
66 call disp%show("count")
67 call disp%show( count )
68 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
69 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
70 call disp%show("array")
71 call disp%show( array, deliml = SK_"""" )
72
73 end do
74 end block
75
76 block
77 integer, allocatable :: array(:)
78 do itry = 1, ntry
79
80 call disp%skip
81 call disp%show("count = getUnifRand(4, 10)")
82 count = getUnifRand(4, 10)
83 call disp%show("array = getUnifRand(0, 9, count) ! generate random array for illustration.")
84 array = getUnifRand(0, 9, count) ! generate random array for illustration.
85 call disp%show("array")
86 call disp%show( array )
87 call disp%show("call setShuffled(array)")
88 call setShuffled(array)
89 call disp%show("array")
90 call disp%show( array )
91
92 call disp%skip
93 call disp%show("count = getUnifRand(0, size(array))")
94 count = getUnifRand(0, size(array))
95 call disp%show("count")
96 call disp%show( count )
97 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
98 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
99 call disp%show("array")
100 call disp%show( array )
101
102 end do
103 end block
104
105 block
106 logical, allocatable :: array(:)
107 do itry = 1, ntry
108
109 call disp%skip
110 call disp%show("count = getUnifRand(4, 10)")
111 count = getUnifRand(4, 10)
112 call disp%show("array = getUnifRand(.false., .true., count) ! generate random array for illustration.")
113 array = getUnifRand(.false., .true., count) ! generate random array for illustration.
114 call disp%show("array")
115 call disp%show( array )
116 call disp%show("call setShuffled(array)")
117 call setShuffled(array)
118 call disp%show("array")
119 call disp%show( array )
120
121 call disp%skip
122 call disp%show("count = getUnifRand(0, size(array))")
123 count = getUnifRand(0, size(array))
124 call disp%show("count")
125 call disp%show( count )
126 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
127 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
128 call disp%show("array")
129 call disp%show( array )
130
131 end do
132 end block
133
134 block
135 complex, allocatable :: array(:)
136 do itry = 1, ntry
137
138 call disp%skip
139 call disp%show("count = getUnifRand(4, 10)")
140 count = getUnifRand(4, 10)
141 call disp%show("array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.")
142 array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
143 call disp%show("array")
144 call disp%show( array )
145 call disp%show("call setShuffled(array)")
146 call setShuffled(array)
147 call disp%show("array")
148 call disp%show( array )
149
150 call disp%skip
151 call disp%show("count = getUnifRand(0, size(array))")
152 count = getUnifRand(0, size(array))
153 call disp%show("count")
154 call disp%show( count )
155 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
156 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
157 call disp%show("array")
158 call disp%show( array )
159
160 end do
161 end block
162
163 block
164 real, allocatable :: array(:)
165 do itry = 1, ntry
166
167 call disp%skip
168 call disp%show("count = getUnifRand(4, 10)")
169 count = getUnifRand(4, 10)
170 call disp%show("array = getUnifRand(0., 1., count) ! generate random array for illustration.")
171 array = getUnifRand(0., 1., count) ! generate random array for illustration.
172 call disp%show("array")
173 call disp%show( array )
174 call disp%show("call setShuffled(array)")
175 call setShuffled(array)
176 call disp%show("array")
177 call disp%show( array )
178
179 call disp%skip
180 call disp%show("count = getUnifRand(0, size(array))")
181 count = getUnifRand(0, size(array))
182 call disp%show("count")
183 call disp%show( count )
184 call disp%show("call setShuffled(array, count) ! draw randomly only `count` elements without replacement.")
185 call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
186 call disp%show("array")
187 call disp%show( array )
188
189 end do
190 end block
191
192end program example
Generate and return a scalar or a contiguous array of rank 1 of length s1 of randomly uniformly distr...
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains classes and procedures for computing various statistical quantities related to t...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter RK
The default real kind in the ParaMonte library: real64 in Fortran, c_double in C-Fortran Interoperati...
Definition: pm_kind.F90:543
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter CK
The default complex kind in the ParaMonte library: real64 in Fortran, c_double_complex in C-Fortran I...
Definition: pm_kind.F90:542
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2count = getUnifRand(4, 10)
3array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
4array
5"GJNOVTNGH"
6call setShuffled(array)
7array
8"GTHONJNGV"
9
10count = getUnifRand(0, len(array))
11count
12+8
13call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
14array
15"HNTONGGVJ"
16
17count = getUnifRand(4, 10)
18array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
19array
20"KBUHYRRC"
21call setShuffled(array)
22array
23"BCUHRKRY"
24
25count = getUnifRand(0, len(array))
26count
27+2
28call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
29array
30"HKUBRCRY"
31
32count = getUnifRand(4, 10)
33array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
34array
35"XJPKWVLU"
36call setShuffled(array)
37array
38"PWXLUJKV"
39
40count = getUnifRand(0, len(array))
41count
42+5
43call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
44array
45"PKXUJLWV"
46
47count = getUnifRand(4, 10)
48array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
49array
50"DJXANXVWBN"
51call setShuffled(array)
52array
53"AJNVXWXDBN"
54
55count = getUnifRand(0, len(array))
56count
57+2
58call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
59array
60"JNAVXWXDBN"
61
62count = getUnifRand(4, 10)
63array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
64array
65"IQWIXFUBM"
66call setShuffled(array)
67array
68"IMBFIUXWQ"
69
70count = getUnifRand(0, len(array))
71count
72+4
73call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
74array
75"XUBQIMIWF"
76
77count = getUnifRand(4, 10)
78array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
79array
80"EMNR"
81call setShuffled(array)
82array
83"MNRE"
84
85count = getUnifRand(0, len(array))
86count
87+2
88call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
89array
90"REMN"
91
92count = getUnifRand(4, 10)
93array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
94array
95"GSHLKMQ"
96call setShuffled(array)
97array
98"GMQKLSH"
99
100count = getUnifRand(0, len(array))
101count
102+3
103call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
104array
105"GHQKLSM"
106
107count = getUnifRand(4, 10)
108array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
109array
110"OYMQLNSB"
111call setShuffled(array)
112array
113"OBYSNQLM"
114
115count = getUnifRand(0, len(array))
116count
117+8
118call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
119array
120"YOLMSQBN"
121
122count = getUnifRand(4, 10)
123array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
124array
125"ZLFIWSKA"
126call setShuffled(array)
127array
128"WFKZISLA"
129
130count = getUnifRand(0, len(array))
131count
132+5
133call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
134array
135"IWKSFZLA"
136
137count = getUnifRand(4, 10)
138array = getUnifRand(repeat('A', count), repeat('Z', count)) ! generate random array for illustration.
139array
140"PONEE"
141call setShuffled(array)
142array
143"ENEOP"
144
145count = getUnifRand(0, len(array))
146count
147+0
148call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
149array
150"ENEOP"
151
152count = getUnifRand(4, 10)
153array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
154array
155"MV", "OJ", "CI", "OV", "BM", "OM"
156call setShuffled(array)
157array
158"BM", "MV", "OV", "OM", "OJ", "CI"
159
160count = getUnifRand(0, size(array))
161count
162+1
163call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
164array
165"OV", "MV", "BM", "OM", "OJ", "CI"
166
167count = getUnifRand(4, 10)
168array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
169array
170"QU", "RK", "HB", "EK", "QM", "IZ", "SU", "CS", "AX", "NE"
171call setShuffled(array)
172array
173"IZ", "HB", "RK", "AX", "QM", "NE", "QU", "EK", "SU", "CS"
174
175count = getUnifRand(0, size(array))
176count
177+0
178call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
179array
180"IZ", "HB", "RK", "AX", "QM", "NE", "QU", "EK", "SU", "CS"
181
182count = getUnifRand(4, 10)
183array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
184array
185"NE", "GO", "BG", "BA", "RS", "QX", "AJ", "QQ", "LQ", "VA"
186call setShuffled(array)
187array
188"BA", "QX", "LQ", "NE", "GO", "BG", "VA", "RS", "AJ", "QQ"
189
190count = getUnifRand(0, size(array))
191count
192+0
193call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
194array
195"BA", "QX", "LQ", "NE", "GO", "BG", "VA", "RS", "AJ", "QQ"
196
197count = getUnifRand(4, 10)
198array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
199array
200"VZ", "JM", "GC", "PH"
201call setShuffled(array)
202array
203"VZ", "PH", "GC", "JM"
204
205count = getUnifRand(0, size(array))
206count
207+0
208call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
209array
210"VZ", "PH", "GC", "JM"
211
212count = getUnifRand(4, 10)
213array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
214array
215"NP", "GP", "HZ", "KM"
216call setShuffled(array)
217array
218"NP", "GP", "KM", "HZ"
219
220count = getUnifRand(0, size(array))
221count
222+3
223call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
224array
225"KM", "GP", "NP", "HZ"
226
227count = getUnifRand(4, 10)
228array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
229array
230"OT", "OQ", "NN", "SG", "RW"
231call setShuffled(array)
232array
233"RW", "NN", "OQ", "OT", "SG"
234
235count = getUnifRand(0, size(array))
236count
237+5
238call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
239array
240"OQ", "NN", "OT", "RW", "SG"
241
242count = getUnifRand(4, 10)
243array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
244array
245"HW", "YC", "UE", "QI"
246call setShuffled(array)
247array
248"UE", "HW", "QI", "YC"
249
250count = getUnifRand(0, size(array))
251count
252+3
253call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
254array
255"QI", "YC", "HW", "UE"
256
257count = getUnifRand(4, 10)
258array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
259array
260"AV", "LF", "WM", "PK", "KP", "MG"
261call setShuffled(array)
262array
263"PK", "WM", "MG", "LF", "KP", "AV"
264
265count = getUnifRand(0, size(array))
266count
267+1
268call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
269array
270"AV", "WM", "MG", "LF", "KP", "PK"
271
272count = getUnifRand(4, 10)
273array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
274array
275"ZD", "MO", "SJ", "ZZ", "MC", "VL"
276call setShuffled(array)
277array
278"ZD", "SJ", "ZZ", "MO", "VL", "MC"
279
280count = getUnifRand(0, size(array))
281count
282+3
283call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
284array
285"ZD", "SJ", "MC", "MO", "VL", "ZZ"
286
287count = getUnifRand(4, 10)
288array = getUnifRand('AA', 'ZZ', count) ! generate random array for illustration.
289array
290"EH", "OI", "OK", "VW", "PN", "XQ", "BN", "ZP"
291call setShuffled(array)
292array
293"BN", "OI", "PN", "OK", "ZP", "VW", "EH", "XQ"
294
295count = getUnifRand(0, size(array))
296count
297+3
298call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
299array
300"PN", "ZP", "XQ", "OK", "OI", "VW", "EH", "BN"
301
302count = getUnifRand(4, 10)
303array = getUnifRand(0, 9, count) ! generate random array for illustration.
304array
305+6, +3, +7, +8, +0, +0, +4, +8, +2, +4
306call setShuffled(array)
307array
308+7, +2, +8, +6, +4, +3, +8, +0, +4, +0
309
310count = getUnifRand(0, size(array))
311count
312+5
313call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
314array
315+2, +8, +3, +8, +4, +6, +7, +0, +4, +0
316
317count = getUnifRand(4, 10)
318array = getUnifRand(0, 9, count) ! generate random array for illustration.
319array
320+2, +3, +9, +7, +0
321call setShuffled(array)
322array
323+3, +9, +0, +2, +7
324
325count = getUnifRand(0, size(array))
326count
327+3
328call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
329array
330+9, +2, +0, +3, +7
331
332count = getUnifRand(4, 10)
333array = getUnifRand(0, 9, count) ! generate random array for illustration.
334array
335+2, +6, +7, +5, +8, +9, +9
336call setShuffled(array)
337array
338+7, +6, +9, +2, +8, +5, +9
339
340count = getUnifRand(0, size(array))
341count
342+7
343call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
344array
345+5, +9, +9, +2, +7, +8, +6
346
347count = getUnifRand(4, 10)
348array = getUnifRand(0, 9, count) ! generate random array for illustration.
349array
350+3, +4, +7, +8, +2, +4, +8
351call setShuffled(array)
352array
353+8, +8, +4, +2, +4, +3, +7
354
355count = getUnifRand(0, size(array))
356count
357+2
358call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
359array
360+3, +4, +8, +2, +4, +8, +7
361
362count = getUnifRand(4, 10)
363array = getUnifRand(0, 9, count) ! generate random array for illustration.
364array
365+8, +6, +4, +3, +6, +9, +1, +2, +1, +3
366call setShuffled(array)
367array
368+6, +9, +1, +1, +2, +6, +3, +3, +8, +4
369
370count = getUnifRand(0, size(array))
371count
372+4
373call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
374array
375+9, +3, +1, +3, +2, +6, +6, +1, +8, +4
376
377count = getUnifRand(4, 10)
378array = getUnifRand(0, 9, count) ! generate random array for illustration.
379array
380+3, +8, +8, +2, +8, +6
381call setShuffled(array)
382array
383+2, +6, +8, +8, +3, +8
384
385count = getUnifRand(0, size(array))
386count
387+1
388call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
389array
390+8, +6, +8, +2, +3, +8
391
392count = getUnifRand(4, 10)
393array = getUnifRand(0, 9, count) ! generate random array for illustration.
394array
395+1, +0, +2, +9, +6
396call setShuffled(array)
397array
398+9, +2, +1, +0, +6
399
400count = getUnifRand(0, size(array))
401count
402+5
403call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
404array
405+1, +6, +9, +0, +2
406
407count = getUnifRand(4, 10)
408array = getUnifRand(0, 9, count) ! generate random array for illustration.
409array
410+5, +3, +7, +5, +7, +1, +2
411call setShuffled(array)
412array
413+2, +5, +1, +7, +3, +7, +5
414
415count = getUnifRand(0, size(array))
416count
417+7
418call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
419array
420+1, +5, +5, +3, +7, +2, +7
421
422count = getUnifRand(4, 10)
423array = getUnifRand(0, 9, count) ! generate random array for illustration.
424array
425+1, +2, +3, +0, +0, +4, +5
426call setShuffled(array)
427array
428+0, +5, +2, +4, +3, +1, +0
429
430count = getUnifRand(0, size(array))
431count
432+2
433call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
434array
435+0, +2, +5, +4, +3, +1, +0
436
437count = getUnifRand(4, 10)
438array = getUnifRand(0, 9, count) ! generate random array for illustration.
439array
440+1, +1, +3, +6, +3, +8, +2
441call setShuffled(array)
442array
443+1, +1, +2, +6, +3, +3, +8
444
445count = getUnifRand(0, size(array))
446count
447+1
448call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
449array
450+3, +1, +2, +6, +3, +1, +8
451
452count = getUnifRand(4, 10)
453array = getUnifRand(.false., .true., count) ! generate random array for illustration.
454array
455T, T, T, F, T, F, T
456call setShuffled(array)
457array
458T, T, F, T, T, F, T
459
460count = getUnifRand(0, size(array))
461count
462+4
463call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
464array
465F, T, T, F, T, T, T
466
467count = getUnifRand(4, 10)
468array = getUnifRand(.false., .true., count) ! generate random array for illustration.
469array
470F, T, T, F, F, T, T, T, T, F
471call setShuffled(array)
472array
473F, T, F, F, T, T, F, T, T, T
474
475count = getUnifRand(0, size(array))
476count
477+9
478call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
479array
480T, T, F, T, F, F, F, T, T, T
481
482count = getUnifRand(4, 10)
483array = getUnifRand(.false., .true., count) ! generate random array for illustration.
484array
485F, F, T, T, T, T
486call setShuffled(array)
487array
488T, T, F, T, F, T
489
490count = getUnifRand(0, size(array))
491count
492+2
493call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
494array
495F, F, T, T, T, T
496
497count = getUnifRand(4, 10)
498array = getUnifRand(.false., .true., count) ! generate random array for illustration.
499array
500F, T, F, T
501call setShuffled(array)
502array
503F, F, T, T
504
505count = getUnifRand(0, size(array))
506count
507+0
508call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
509array
510F, F, T, T
511
512count = getUnifRand(4, 10)
513array = getUnifRand(.false., .true., count) ! generate random array for illustration.
514array
515F, F, F, F, T, F, F, F, T
516call setShuffled(array)
517array
518T, F, F, T, F, F, F, F, F
519
520count = getUnifRand(0, size(array))
521count
522+0
523call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
524array
525T, F, F, T, F, F, F, F, F
526
527count = getUnifRand(4, 10)
528array = getUnifRand(.false., .true., count) ! generate random array for illustration.
529array
530F, T, F, T, F, F, F
531call setShuffled(array)
532array
533F, F, F, F, T, T, F
534
535count = getUnifRand(0, size(array))
536count
537+7
538call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
539array
540F, T, F, F, F, F, T
541
542count = getUnifRand(4, 10)
543array = getUnifRand(.false., .true., count) ! generate random array for illustration.
544array
545T, T, T, F
546call setShuffled(array)
547array
548T, T, F, T
549
550count = getUnifRand(0, size(array))
551count
552+2
553call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
554array
555F, T, T, T
556
557count = getUnifRand(4, 10)
558array = getUnifRand(.false., .true., count) ! generate random array for illustration.
559array
560T, F, F, F, F
561call setShuffled(array)
562array
563F, F, T, F, F
564
565count = getUnifRand(0, size(array))
566count
567+2
568call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
569array
570F, F, T, F, F
571
572count = getUnifRand(4, 10)
573array = getUnifRand(.false., .true., count) ! generate random array for illustration.
574array
575T, F, T, F
576call setShuffled(array)
577array
578F, T, T, F
579
580count = getUnifRand(0, size(array))
581count
582+1
583call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
584array
585T, T, F, F
586
587count = getUnifRand(4, 10)
588array = getUnifRand(.false., .true., count) ! generate random array for illustration.
589array
590F, T, F, T
591call setShuffled(array)
592array
593F, F, T, T
594
595count = getUnifRand(0, size(array))
596count
597+2
598call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
599array
600T, F, T, F
601
602count = getUnifRand(4, 10)
603array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
604array
605(+0.834680915, +0.373537838), (+0.455232263, +0.944435596E-3), (+0.143759429, +0.508736908), (+0.428740501, +0.849342763), (+0.488647282, +0.452931702), (+0.708962917, +0.124783278), (+0.796450853, +0.823142469), (+0.684611917, +0.179897964)
606call setShuffled(array)
607array
608(+0.428740501, +0.849342763), (+0.488647282, +0.452931702), (+0.708962917, +0.124783278), (+0.684611917, +0.179897964), (+0.455232263, +0.944435596E-3), (+0.834680915, +0.373537838), (+0.796450853, +0.823142469), (+0.143759429, +0.508736908)
609
610count = getUnifRand(0, size(array))
611count
612+7
613call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
614array
615(+0.834680915, +0.373537838), (+0.488647282, +0.452931702), (+0.428740501, +0.849342763), (+0.455232263, +0.944435596E-3), (+0.143759429, +0.508736908), (+0.708962917, +0.124783278), (+0.684611917, +0.179897964), (+0.796450853, +0.823142469)
616
617count = getUnifRand(4, 10)
618array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
619array
620(+0.511983097, +0.321241379), (+0.245675802, +0.869327128), (+0.998765171, +0.390220284E-1), (+0.236380100, +0.671525359), (+0.214736223, +0.507051766), (+0.940484405, +0.420090318), (+0.410217226, +0.869851232)
621call setShuffled(array)
622array
623(+0.940484405, +0.420090318), (+0.236380100, +0.671525359), (+0.245675802, +0.869327128), (+0.511983097, +0.321241379), (+0.214736223, +0.507051766), (+0.410217226, +0.869851232), (+0.998765171, +0.390220284E-1)
624
625count = getUnifRand(0, size(array))
626count
627+4
628call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
629array
630(+0.998765171, +0.390220284E-1), (+0.940484405, +0.420090318), (+0.245675802, +0.869327128), (+0.236380100, +0.671525359), (+0.214736223, +0.507051766), (+0.410217226, +0.869851232), (+0.511983097, +0.321241379)
631
632count = getUnifRand(4, 10)
633array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
634array
635(+0.660359502, +0.793549061), (+0.992908955, +0.778287292), (+0.581238091, +0.658040583), (+0.761271179, +0.595197797), (+0.361036658, +0.589399993), (+0.744804144, +0.488637745), (+0.497796595, +0.616843879), (+0.965064764E-2, +0.161347449), (+0.710910857, +0.675622165), (+0.173549712, +0.370471001)
636call setShuffled(array)
637array
638(+0.710910857, +0.675622165), (+0.581238091, +0.658040583), (+0.992908955, +0.778287292), (+0.965064764E-2, +0.161347449), (+0.744804144, +0.488637745), (+0.660359502, +0.793549061), (+0.761271179, +0.595197797), (+0.497796595, +0.616843879), (+0.361036658, +0.589399993), (+0.173549712, +0.370471001)
639
640count = getUnifRand(0, size(array))
641count
642+1
643call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
644array
645(+0.710910857, +0.675622165), (+0.581238091, +0.658040583), (+0.992908955, +0.778287292), (+0.965064764E-2, +0.161347449), (+0.744804144, +0.488637745), (+0.660359502, +0.793549061), (+0.761271179, +0.595197797), (+0.497796595, +0.616843879), (+0.361036658, +0.589399993), (+0.173549712, +0.370471001)
646
647count = getUnifRand(4, 10)
648array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
649array
650(+0.674531221, +0.709053636), (+0.760627270, +0.328963757), (+0.746077597, +0.551066399), (+0.653535664, +0.743193448), (+0.708052754, +0.126029074), (+0.112686098, +0.337355077), (+0.904179811E-1, +0.493658304)
651call setShuffled(array)
652array
653(+0.760627270, +0.328963757), (+0.746077597, +0.551066399), (+0.708052754, +0.126029074), (+0.112686098, +0.337355077), (+0.904179811E-1, +0.493658304), (+0.653535664, +0.743193448), (+0.674531221, +0.709053636)
654
655count = getUnifRand(0, size(array))
656count
657+2
658call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
659array
660(+0.653535664, +0.743193448), (+0.708052754, +0.126029074), (+0.746077597, +0.551066399), (+0.112686098, +0.337355077), (+0.904179811E-1, +0.493658304), (+0.760627270, +0.328963757), (+0.674531221, +0.709053636)
661
662count = getUnifRand(4, 10)
663array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
664array
665(+0.834695697, +0.123252094), (+0.433920145, +0.303880274), (+0.395114660, +0.735439956), (+0.153032184, +0.201784492), (+0.458145022, +0.709687293)
666call setShuffled(array)
667array
668(+0.433920145, +0.303880274), (+0.834695697, +0.123252094), (+0.395114660, +0.735439956), (+0.458145022, +0.709687293), (+0.153032184, +0.201784492)
669
670count = getUnifRand(0, size(array))
671count
672+2
673call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
674array
675(+0.458145022, +0.709687293), (+0.153032184, +0.201784492), (+0.395114660, +0.735439956), (+0.433920145, +0.303880274), (+0.834695697, +0.123252094)
676
677count = getUnifRand(4, 10)
678array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
679array
680(+0.963831723, +0.636827350), (+0.378730714, +0.320274115), (+0.281570494, +0.953615904), (+0.400461137, +0.389462471), (+0.247055292, +0.853823841), (+0.965692282, +0.335247576), (+0.765965998, +0.517767668)
681call setShuffled(array)
682array
683(+0.281570494, +0.953615904), (+0.247055292, +0.853823841), (+0.765965998, +0.517767668), (+0.378730714, +0.320274115), (+0.400461137, +0.389462471), (+0.965692282, +0.335247576), (+0.963831723, +0.636827350)
684
685count = getUnifRand(0, size(array))
686count
687+0
688call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
689array
690(+0.281570494, +0.953615904), (+0.247055292, +0.853823841), (+0.765965998, +0.517767668), (+0.378730714, +0.320274115), (+0.400461137, +0.389462471), (+0.965692282, +0.335247576), (+0.963831723, +0.636827350)
691
692count = getUnifRand(4, 10)
693array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
694array
695(+0.750934899, +0.327126324), (+0.658757687E-1, +0.571905077), (+0.253057063, +0.152806342), (+0.602365077, +0.355686128)
696call setShuffled(array)
697array
698(+0.658757687E-1, +0.571905077), (+0.602365077, +0.355686128), (+0.253057063, +0.152806342), (+0.750934899, +0.327126324)
699
700count = getUnifRand(0, size(array))
701count
702+4
703call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
704array
705(+0.253057063, +0.152806342), (+0.750934899, +0.327126324), (+0.658757687E-1, +0.571905077), (+0.602365077, +0.355686128)
706
707count = getUnifRand(4, 10)
708array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
709array
710(+0.754587114, +0.308714628), (+0.678682745, +0.534056962), (+0.419425070, +0.558920503), (+0.972943425, +0.490928829), (+0.897468805, +0.412264049), (+0.862294436E-1, +0.240212142), (+0.882552207, +0.868682265E-1), (+0.314425051, +0.231942058)
711call setShuffled(array)
712array
713(+0.897468805, +0.412264049), (+0.678682745, +0.534056962), (+0.862294436E-1, +0.240212142), (+0.419425070, +0.558920503), (+0.314425051, +0.231942058), (+0.754587114, +0.308714628), (+0.882552207, +0.868682265E-1), (+0.972943425, +0.490928829)
714
715count = getUnifRand(0, size(array))
716count
717+2
718call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
719array
720(+0.862294436E-1, +0.240212142), (+0.314425051, +0.231942058), (+0.897468805, +0.412264049), (+0.419425070, +0.558920503), (+0.678682745, +0.534056962), (+0.754587114, +0.308714628), (+0.882552207, +0.868682265E-1), (+0.972943425, +0.490928829)
721
722count = getUnifRand(4, 10)
723array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
724array
725(+0.949395537, +0.258144438), (+0.566200614, +0.784127653), (+0.853508353, +0.570670128), (+0.497632027E-1, +0.582485914), (+0.794579208, +0.631176829), (+0.731608033, +0.599373341), (+0.450123072, +0.294433832E-1), (+0.159482837, +0.950143635)
726call setShuffled(array)
727array
728(+0.794579208, +0.631176829), (+0.853508353, +0.570670128), (+0.731608033, +0.599373341), (+0.497632027E-1, +0.582485914), (+0.566200614, +0.784127653), (+0.159482837, +0.950143635), (+0.949395537, +0.258144438), (+0.450123072, +0.294433832E-1)
729
730count = getUnifRand(0, size(array))
731count
732+2
733call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
734array
735(+0.731608033, +0.599373341), (+0.949395537, +0.258144438), (+0.794579208, +0.631176829), (+0.497632027E-1, +0.582485914), (+0.566200614, +0.784127653), (+0.159482837, +0.950143635), (+0.853508353, +0.570670128), (+0.450123072, +0.294433832E-1)
736
737count = getUnifRand(4, 10)
738array = getUnifRand((0., 0.), (1., 1.), count) ! generate random array for illustration.
739array
740(+0.183834136, +0.600032449), (+0.840258837, +0.614135087), (+0.136981428, +0.333466947), (+0.612133622, +0.780205131), (+0.204359412, +0.368407011)
741call setShuffled(array)
742array
743(+0.840258837, +0.614135087), (+0.204359412, +0.368407011), (+0.612133622, +0.780205131), (+0.136981428, +0.333466947), (+0.183834136, +0.600032449)
744
745count = getUnifRand(0, size(array))
746count
747+1
748call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
749array
750(+0.183834136, +0.600032449), (+0.204359412, +0.368407011), (+0.612133622, +0.780205131), (+0.136981428, +0.333466947), (+0.840258837, +0.614135087)
751
752count = getUnifRand(4, 10)
753array = getUnifRand(0., 1., count) ! generate random array for illustration.
754array
755+0.731208444, +0.677431405, +0.411407888, +0.318547785, +0.147988319, +0.622487724, +0.441724658E-1, +0.259052634
756call setShuffled(array)
757array
758+0.731208444, +0.677431405, +0.147988319, +0.259052634, +0.441724658E-1, +0.622487724, +0.318547785, +0.411407888
759
760count = getUnifRand(0, size(array))
761count
762+5
763call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
764array
765+0.147988319, +0.259052634, +0.441724658E-1, +0.677431405, +0.318547785, +0.622487724, +0.731208444, +0.411407888
766
767count = getUnifRand(4, 10)
768array = getUnifRand(0., 1., count) ! generate random array for illustration.
769array
770+0.219860852, +0.537576556, +0.804618239, +0.496696591, +0.415843666, +0.111097097, +0.739349961, +0.911193967
771call setShuffled(array)
772array
773+0.219860852, +0.415843666, +0.911193967, +0.804618239, +0.111097097, +0.739349961, +0.537576556, +0.496696591
774
775count = getUnifRand(0, size(array))
776count
777+1
778call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
779array
780+0.804618239, +0.415843666, +0.911193967, +0.219860852, +0.111097097, +0.739349961, +0.537576556, +0.496696591
781
782count = getUnifRand(4, 10)
783array = getUnifRand(0., 1., count) ! generate random array for illustration.
784array
785+0.301275849, +0.649399281, +0.514105320, +0.657246113, +0.524138868, +0.654278398E-1, +0.736789227, +0.251535118, +0.525406957
786call setShuffled(array)
787array
788+0.649399281, +0.654278398E-1, +0.525406957, +0.514105320, +0.524138868, +0.301275849, +0.657246113, +0.736789227, +0.251535118
789
790count = getUnifRand(0, size(array))
791count
792+4
793call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
794array
795+0.654278398E-1, +0.514105320, +0.524138868, +0.251535118, +0.525406957, +0.301275849, +0.657246113, +0.736789227, +0.649399281
796
797count = getUnifRand(4, 10)
798array = getUnifRand(0., 1., count) ! generate random array for illustration.
799array
800+0.291693270, +0.275457978, +0.256953239, +0.233196735, +0.552217543
801call setShuffled(array)
802array
803+0.256953239, +0.233196735, +0.552217543, +0.291693270, +0.275457978
804
805count = getUnifRand(0, size(array))
806count
807+5
808call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
809array
810+0.233196735, +0.291693270, +0.275457978, +0.552217543, +0.256953239
811
812count = getUnifRand(4, 10)
813array = getUnifRand(0., 1., count) ! generate random array for illustration.
814array
815+0.951786816, +0.291652143, +0.206996024, +0.623316526, +0.558506906, +0.547552049, +0.143187046E-1
816call setShuffled(array)
817array
818+0.206996024, +0.623316526, +0.143187046E-1, +0.547552049, +0.558506906, +0.291652143, +0.951786816
819
820count = getUnifRand(0, size(array))
821count
822+5
823call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
824array
825+0.143187046E-1, +0.558506906, +0.206996024, +0.951786816, +0.291652143, +0.623316526, +0.547552049
826
827count = getUnifRand(4, 10)
828array = getUnifRand(0., 1., count) ! generate random array for illustration.
829array
830+0.952786744, +0.168502927E-1, +0.700375438, +0.599286497, +0.571049988, +0.916320622, +0.958574414, +0.776775718, +0.744182289
831call setShuffled(array)
832array
833+0.952786744, +0.916320622, +0.700375438, +0.571049988, +0.599286497, +0.168502927E-1, +0.958574414, +0.776775718, +0.744182289
834
835count = getUnifRand(0, size(array))
836count
837+8
838call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
839array
840+0.958574414, +0.776775718, +0.916320622, +0.168502927E-1, +0.744182289, +0.599286497, +0.700375438, +0.952786744, +0.571049988
841
842count = getUnifRand(4, 10)
843array = getUnifRand(0., 1., count) ! generate random array for illustration.
844array
845+0.754724145E-1, +0.917694151, +0.172486305E-1, +0.924230397, +0.605927527, +0.742885530, +0.878512383, +0.517113924, +0.154757917, +0.644013703
846call setShuffled(array)
847array
848+0.644013703, +0.924230397, +0.172486305E-1, +0.742885530, +0.917694151, +0.878512383, +0.605927527, +0.517113924, +0.154757917, +0.754724145E-1
849
850count = getUnifRand(0, size(array))
851count
852+1
853call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
854array
855+0.742885530, +0.924230397, +0.172486305E-1, +0.644013703, +0.917694151, +0.878512383, +0.605927527, +0.517113924, +0.154757917, +0.754724145E-1
856
857count = getUnifRand(4, 10)
858array = getUnifRand(0., 1., count) ! generate random array for illustration.
859array
860+0.293726325E-1, +0.936989665, +0.497731805, +0.315658152, +0.982578814, +0.893484950, +0.897144973
861call setShuffled(array)
862array
863+0.893484950, +0.293726325E-1, +0.897144973, +0.497731805, +0.315658152, +0.982578814, +0.936989665
864
865count = getUnifRand(0, size(array))
866count
867+0
868call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
869array
870+0.893484950, +0.293726325E-1, +0.897144973, +0.497731805, +0.315658152, +0.982578814, +0.936989665
871
872count = getUnifRand(4, 10)
873array = getUnifRand(0., 1., count) ! generate random array for illustration.
874array
875+0.849202693, +0.768660307, +0.863514185, +0.836149454, +0.154337108, +0.666713715E-1, +0.230043352, +0.196436882
876call setShuffled(array)
877array
878+0.196436882, +0.154337108, +0.666713715E-1, +0.768660307, +0.863514185, +0.230043352, +0.849202693, +0.836149454
879
880count = getUnifRand(0, size(array))
881count
882+1
883call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
884array
885+0.836149454, +0.154337108, +0.666713715E-1, +0.768660307, +0.863514185, +0.230043352, +0.849202693, +0.196436882
886
887count = getUnifRand(4, 10)
888array = getUnifRand(0., 1., count) ! generate random array for illustration.
889array
890+0.161709487, +0.314184189, +0.871208906, +0.353571177, +0.520778716, +0.575232625, +0.973841310
891call setShuffled(array)
892array
893+0.314184189, +0.973841310, +0.871208906, +0.520778716, +0.575232625, +0.353571177, +0.161709487
894
895count = getUnifRand(0, size(array))
896count
897+2
898call setShuffled(array, count) ! draw randomly only `count` elements without replacement.
899array
900+0.575232625, +0.314184189, +0.871208906, +0.520778716, +0.973841310, +0.353571177, +0.161709487
901
Test:
test_pm_arrayShuffle
Todo:
Low Priority: This generic interface can be extended to 2D input objects.
Todo:
High Priority: Update 2021: This task is now resolved.
The current random integer generator uses a simple double precision real conversion to integer values.
While this works fairly well for most use cases, it may biased for generating random integer of kind IK4.
A future remedy should use Bitmask with Rejection as described here.
As of 2021, the use of double precision (64-bit) vs. single-precision for random number generation increases the computational cost of the algorithms by about three times.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Amir Shahmoradi, September 1, 2017, 12:00 AM, Institute for Computational Engineering and Sciences (ICES), The University of Texas Austin

Definition at line 688 of file pm_arrayShuffle.F90.


The documentation for this interface was generated from the following file: