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

Generate and return a randomly-uniform selected sequence of elements from a scalar character or integer range specified via the input limits [start, stop].
More...

Detailed Description

Generate and return a randomly-uniform selected sequence of elements from a scalar character or integer range specified via the input limits [start, stop].

Should the sequence elements be unique, the length of the output sequence must be smaller than or equal to the specified range as [start, stop].

Parameters
[in]count: The input non-negative scalar integer of default kind IK, representing the length of the output sequence of choices in the range specified by [start, stop].
If unique = .true., the condition count <= len(getRange(start, stop, step)) or count <= size(getRange(start, stop, step)) must hold to ensure uniqueness of the elements of the output sequence.
[in]start: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]stop: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]step: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
[in]unique: See the documentation of the corresponding argument of setChange(rng, change, start, stop, step, unique).
(optional, default = .false._LK)
Returns
change : The output vector of size count,
  1. type integer of kind any supported by the processor (e.g., IK, IK8, IK16, IK32, or IK64),
or a scalar of,
  1. type character of kind any supported by the processor (e.g., SK, SKA, SKD , or SKU) of length count,
whose elements are uniformly randomly selected from within the range getRange(start, stop, step).


Possible calling interfaces

change = getChange(count, start, stop, step, unique = unique)
Generate and return a randomly-uniform selected sequence of elements from a scalar character or integ...
This module contains procedures and generic interfaces for selecting uniformly-distributed random cho...
Warning
All warnings and conditions associated with getRange(start, stop, step) and setChoice(start, stop, step) equally hold for the procedures of this generic interface.
The length of the resulting sequence from the specified range (start, stop, step) must not be zero.
These conditions are verified only if the library is built with the preprocessor macro CHECK_ENABLED=1.
Remarks
The procedures under discussion are impure.
See also
isHead
getChange
setChange
getChoice
setChoice
getUnifRand
setUnifRand
getShuffled
setShuffled
getRemapped
setRemapped


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_arrayRange, only: getRange
10 use pm_arrayChoice, only: getChoice
11 use pm_distUnif, only: getUnifRand
12 use pm_arrayChange, only: getChange
13
14 implicit none
15
16 integer(IK) :: count, itry, ntry = 10
17 type(display_type) :: disp
18 disp = display_type(file = "main.out.F90")
19
20 block
21 integer(IK) :: step
22 character(:), allocatable :: start, stop, change
23
24 do itry = 1, 2
25 call disp%skip
26 call disp%show("count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])")
27 count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
28 call disp%show("count")
29 call disp%show( count )
30 call disp%show("change = getChange(count, start, stop, step)")
31 change = getChange(count, start, stop, step)
32 call disp%show("change")
33 call disp%show( change, deliml = SK_"""" )
34 end do
35
36 do itry = 1, ntry
37
38 call disp%skip
39 call disp%show("count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1")
40 count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
41 call disp%show("count")
42 call disp%show( count )
43 call disp%show("change = getChange(count, start, stop, step)")
44 change = getChange(count, start, stop, step)
45 call disp%show("change")
46 call disp%show( change, deliml = SK_"""" )
47
48 call disp%skip
49 call disp%show("count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1")
50 count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
51 call disp%show("count")
52 call disp%show( count )
53 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
54 change = getChange(count, start, stop, step, unique = .true._LK)
55 call disp%show("change")
56 call disp%show( change, deliml = SK_"""" )
57
58 call disp%skip
59 call disp%show("count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3")
60 count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
61 call disp%show("count")
62 call disp%show( count )
63 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
64 change = getChange(count, start, stop, step, unique = .true._LK)
65 call disp%show("change")
66 call disp%show( change, deliml = SK_"""" )
67
68 end do
69 end block
70
71 block
72 use pm_kind, only: IKG => IK ! all integer kinds are supported.
73 integer(IKG) :: step
74 integer(IKG), allocatable :: start, stop, change(:)
75 do itry = 1, ntry
76
77 call disp%skip
78 call disp%show("count = getUnifRand(1, 10); start = 0; stop = 9; step = 1")
79 count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
80 call disp%show("count")
81 call disp%show( count )
82 call disp%show("change = getChange(count, start, stop, step)")
83 change = getChange(count, start, stop, step)
84 call disp%show("change")
85 call disp%show( change, deliml = SK_"""" )
86
87 call disp%skip
88 call disp%show("count = getUnifRand(5, 10); start = 9; stop = -9; step = -2")
89 count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
90 call disp%show("count")
91 call disp%show( count )
92 call disp%show("change = getChange(count, start, stop, step, unique = .true._LK)")
93 change = getChange(count, start, stop, step, unique = .true._LK)
94 call disp%show("change")
95 call disp%show( change, deliml = SK_"""" )
96
97 call disp%skip
98 call disp%show("count = getUnifRand(5, 15); start = 5; stop = 1; step = -2")
99 count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
100 call disp%show("count")
101 call disp%show( count )
102 call disp%show("change = getChange(count, start, stop, step, unique = .false._LK)")
103 change = getChange(count, start, stop, step, unique = .false._LK)
104 call disp%show("change")
105 call disp%show( change, deliml = SK_"""" )
106
107 end do
108 end block
109
110end program example
Select a single (or multiple) element(s) from the input array of intrinsic type of arbitrary kind ran...
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
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 procedures and generic interfaces for selecting uniformly-distributed or arbitra...
This module contains procedures and generic interfaces for generating ranges of discrete character,...
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 = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
3count
4+2
5change = getChange(count, start, stop, step)
6change
7"AA"
8
9count = getChoice([1, 2]); start = 'A'; stop = 'A'; step = getChoice([-1, 1])
10count
11+1
12change = getChange(count, start, stop, step)
13change
14"A"
15
16count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
17count
18+7
19change = getChange(count, start, stop, step)
20change
21"EFCCBAB"
22
23count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
24count
25+5
26change = getChange(count, start, stop, step, unique = .true._LK)
27change
28"BFCDE"
29
30count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
31count
32+5
33change = getChange(count, start, stop, step, unique = .true._LK)
34change
35"G_hPk"
36
37count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
38count
39+4
40change = getChange(count, start, stop, step)
41change
42"BDFA"
43
44count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
45count
46+3
47change = getChange(count, start, stop, step, unique = .true._LK)
48change
49"BCD"
50
51count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
52count
53+6
54change = getChange(count, start, stop, step, unique = .true._LK)
55change
56"JS\PDn"
57
58count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
59count
60+4
61change = getChange(count, start, stop, step)
62change
63"AEAF"
64
65count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
66count
67+6
68change = getChange(count, start, stop, step, unique = .true._LK)
69change
70"FCABED"
71
72count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
73count
74+6
75change = getChange(count, start, stop, step, unique = .true._LK)
76change
77"Y_bDS\"
78
79count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
80count
81+10
82change = getChange(count, start, stop, step)
83change
84"CBECFAFEEA"
85
86count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
87count
88+2
89change = getChange(count, start, stop, step, unique = .true._LK)
90change
91"FD"
92
93count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
94count
95+6
96change = getChange(count, start, stop, step, unique = .true._LK)
97change
98"YDzJPM"
99
100count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
101count
102+3
103change = getChange(count, start, stop, step)
104change
105"BAA"
106
107count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
108count
109+5
110change = getChange(count, start, stop, step, unique = .true._LK)
111change
112"FDBEA"
113
114count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
115count
116+9
117change = getChange(count, start, stop, step, unique = .true._LK)
118change
119"qA_JDknGt"
120
121count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
122count
123+9
124change = getChange(count, start, stop, step)
125change
126"FABDEADCB"
127
128count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
129count
130+6
131change = getChange(count, start, stop, step, unique = .true._LK)
132change
133"ACDFEB"
134
135count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
136count
137+8
138change = getChange(count, start, stop, step, unique = .true._LK)
139change
140"nV\ewPAt"
141
142count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
143count
144+8
145change = getChange(count, start, stop, step)
146change
147"EECFEBFC"
148
149count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
150count
151+2
152change = getChange(count, start, stop, step, unique = .true._LK)
153change
154"BC"
155
156count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
157count
158+10
159change = getChange(count, start, stop, step, unique = .true._LK)
160change
161"SYnzMtwekP"
162
163count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
164count
165+1
166change = getChange(count, start, stop, step)
167change
168"B"
169
170count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
171count
172+6
173change = getChange(count, start, stop, step, unique = .true._LK)
174change
175"AFDCBE"
176
177count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
178count
179+8
180change = getChange(count, start, stop, step, unique = .true._LK)
181change
182"YJk_whDA"
183
184count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
185count
186+10
187change = getChange(count, start, stop, step)
188change
189"BADADFBDFD"
190
191count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
192count
193+4
194change = getChange(count, start, stop, step, unique = .true._LK)
195change
196"CEAF"
197
198count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
199count
200+8
201change = getChange(count, start, stop, step, unique = .true._LK)
202change
203"J_VqzSwY"
204
205count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
206count
207+1
208change = getChange(count, start, stop, step)
209change
210"B"
211
212count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
213count
214+2
215change = getChange(count, start, stop, step, unique = .true._LK)
216change
217"DE"
218
219count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
220count
221+7
222change = getChange(count, start, stop, step, unique = .true._LK)
223change
224"Ywqhbzn"
225
226count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
227count
228+1
229change = getChange(count, start, stop, step)
230change
231"+5"
232
233count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
234count
235+10
236change = getChange(count, start, stop, step, unique = .true._LK)
237change
238"-7", "-3", "+9", "-5", "-1", "+5", "+7", "+3", "+1", "-9"
239
240count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
241count
242+10
243change = getChange(count, start, stop, step, unique = .false._LK)
244change
245"+5", "+3", "+5", "+3", "+3", "+3", "+5", "+1", "+3", "+1"
246
247count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
248count
249+7
250change = getChange(count, start, stop, step)
251change
252"+4", "+1", "+7", "+6", "+8", "+1", "+5"
253
254count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
255count
256+10
257change = getChange(count, start, stop, step, unique = .true._LK)
258change
259"+7", "+1", "-1", "+9", "-7", "-9", "+5", "-3", "-5", "+3"
260
261count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
262count
263+13
264change = getChange(count, start, stop, step, unique = .false._LK)
265change
266"+1", "+5", "+1", "+3", "+5", "+1", "+1", "+1", "+5", "+1", "+3", "+3", "+1"
267
268count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
269count
270+2
271change = getChange(count, start, stop, step)
272change
273"+1", "+6"
274
275count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
276count
277+8
278change = getChange(count, start, stop, step, unique = .true._LK)
279change
280"+7", "+3", "-7", "+1", "-3", "-1", "+5", "-9"
281
282count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
283count
284+13
285change = getChange(count, start, stop, step, unique = .false._LK)
286change
287"+5", "+3", "+3", "+1", "+3", "+3", "+3", "+3", "+5", "+5", "+5", "+5", "+1"
288
289count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
290count
291+7
292change = getChange(count, start, stop, step)
293change
294"+4", "+6", "+6", "+5", "+1", "+7", "+2"
295
296count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
297count
298+7
299change = getChange(count, start, stop, step, unique = .true._LK)
300change
301"+1", "+3", "-5", "+9", "+5", "-3", "-1"
302
303count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
304count
305+14
306change = getChange(count, start, stop, step, unique = .false._LK)
307change
308"+3", "+1", "+5", "+3", "+1", "+5", "+3", "+5", "+1", "+1", "+5", "+5", "+1", "+3"
309
310count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
311count
312+10
313change = getChange(count, start, stop, step)
314change
315"+9", "+1", "+7", "+0", "+9", "+5", "+3", "+6", "+9", "+8"
316
317count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
318count
319+5
320change = getChange(count, start, stop, step, unique = .true._LK)
321change
322"+5", "-5", "-3", "+3", "+7"
323
324count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
325count
326+13
327change = getChange(count, start, stop, step, unique = .false._LK)
328change
329"+5", "+1", "+1", "+1", "+5", "+1", "+3", "+3", "+3", "+3", "+1", "+5", "+3"
330
331count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
332count
333+5
334change = getChange(count, start, stop, step)
335change
336"+1", "+6", "+6", "+9", "+1"
337
338count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
339count
340+9
341change = getChange(count, start, stop, step, unique = .true._LK)
342change
343"-1", "+7", "+3", "-3", "-9", "-5", "+5", "-7", "+1"
344
345count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
346count
347+15
348change = getChange(count, start, stop, step, unique = .false._LK)
349change
350"+5", "+1", "+1", "+5", "+3", "+3", "+5", "+1", "+3", "+3", "+5", "+1", "+1", "+5", "+5"
351
352count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
353count
354+6
355change = getChange(count, start, stop, step)
356change
357"+1", "+4", "+4", "+6", "+0", "+0"
358
359count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
360count
361+5
362change = getChange(count, start, stop, step, unique = .true._LK)
363change
364"-3", "+9", "-9", "-7", "+5"
365
366count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
367count
368+13
369change = getChange(count, start, stop, step, unique = .false._LK)
370change
371"+5", "+5", "+5", "+5", "+3", "+5", "+1", "+3", "+3", "+5", "+5", "+5", "+3"
372
373count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
374count
375+9
376change = getChange(count, start, stop, step)
377change
378"+8", "+9", "+7", "+6", "+4", "+4", "+1", "+5", "+5"
379
380count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
381count
382+6
383change = getChange(count, start, stop, step, unique = .true._LK)
384change
385"-7", "-9", "+5", "-1", "-3", "-5"
386
387count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
388count
389+11
390change = getChange(count, start, stop, step, unique = .false._LK)
391change
392"+1", "+5", "+1", "+3", "+1", "+3", "+5", "+3", "+1", "+5", "+3"
393
394count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
395count
396+5
397change = getChange(count, start, stop, step)
398change
399"+4", "+3", "+0", "+8", "+2"
400
401count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
402count
403+7
404change = getChange(count, start, stop, step, unique = .true._LK)
405change
406"-3", "+9", "-9", "+5", "-5", "+1", "-1"
407
408count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
409count
410+7
411change = getChange(count, start, stop, step, unique = .false._LK)
412change
413"+1", "+1", "+1", "+1", "+3", "+1", "+3"
414
415count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
416count
417+4
418change = getChange(count, start, stop, step)
419change
420"+4", "+4", "+9", "+3"
421
422count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
423count
424+5
425change = getChange(count, start, stop, step, unique = .true._LK)
426change
427"-7", "-9", "+5", "+7", "-1"
428
429count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
430count
431+7
432change = getChange(count, start, stop, step, unique = .false._LK)
433change
434"+3", "+5", "+3", "+5", "+5", "+3", "+3"
435
Test:
test_pm_arrayChange
Todo:
The input argument step can be made optional.
Currently, it is a required argument to avoid testing complexities in the case of input real-valued ranges.


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, Monday March 6, 2017, 3:22 pm, Institute for Computational Engineering and Sciences (ICES), The University of Texas at Austin.

Definition at line 138 of file pm_arrayChange.F90.


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