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+10
19change = getChange(count, start, stop, step)
20change
21"AABDFEFFAF"
22
23count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
24count
25+3
26change = getChange(count, start, stop, step, unique = .true._LK)
27change
28"EBC"
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"beY\S"
36
37count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
38count
39+8
40change = getChange(count, start, stop, step)
41change
42"DDEACAFA"
43
44count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
45count
46+2
47change = getChange(count, start, stop, step, unique = .true._LK)
48change
49"DF"
50
51count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
52count
53+9
54change = getChange(count, start, stop, step, unique = .true._LK)
55change
56"GMknYD_Je"
57
58count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
59count
60+8
61change = getChange(count, start, stop, step)
62change
63"DBADAAFF"
64
65count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
66count
67+2
68change = getChange(count, start, stop, step, unique = .true._LK)
69change
70"FD"
71
72count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
73count
74+8
75change = getChange(count, start, stop, step, unique = .true._LK)
76change
77"bYDMAnSz"
78
79count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
80count
81+8
82change = getChange(count, start, stop, step)
83change
84"CDDBABED"
85
86count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
87count
88+1
89change = getChange(count, start, stop, step, unique = .true._LK)
90change
91"F"
92
93count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
94count
95+8
96change = getChange(count, start, stop, step, unique = .true._LK)
97change
98"JwkGneM_"
99
100count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
101count
102+10
103change = getChange(count, start, stop, step)
104change
105"BCCDEDEBCF"
106
107count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
108count
109+3
110change = getChange(count, start, stop, step, unique = .true._LK)
111change
112"FCB"
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"wJtYhVDGP"
120
121count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
122count
123+4
124change = getChange(count, start, stop, step)
125change
126"DDBB"
127
128count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
129count
130+5
131change = getChange(count, start, stop, step, unique = .true._LK)
132change
133"BADEF"
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"q\knYJ_V"
141
142count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
143count
144+4
145change = getChange(count, start, stop, step)
146change
147"FDEC"
148
149count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
150count
151+1
152change = getChange(count, start, stop, step, unique = .true._LK)
153change
154"D"
155
156count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
157count
158+6
159change = getChange(count, start, stop, step, unique = .true._LK)
160change
161"eVMPY\"
162
163count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
164count
165+6
166change = getChange(count, start, stop, step)
167change
168"BFCEFF"
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"FBCADE"
176
177count = getUnifRand(5, 10); start = 'A'; stop = 'z'; step = 3
178count
179+6
180change = getChange(count, start, stop, step, unique = .true._LK)
181change
182"zbAJDP"
183
184count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
185count
186+5
187change = getChange(count, start, stop, step)
188change
189"DBBDA"
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"DBFC"
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"_eb\AJqw"
204
205count = getUnifRand(1, 10); start = 'A'; stop = 'F'; step = 1
206count
207+8
208change = getChange(count, start, stop, step)
209change
210"FFEDEBCD"
211
212count = getUnifRand(1, 6); start = 'F'; stop = 'A'; step = -1
213count
214+1
215change = getChange(count, start, stop, step, unique = .true._LK)
216change
217"A"
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"GqP\Jzk"
225
226count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
227count
228+2
229change = getChange(count, start, stop, step)
230change
231"+2", "+1"
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"-9", "+1", "+9", "+5", "-5", "+3", "-3", "+7", "-1", "-7"
239
240count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
241count
242+12
243change = getChange(count, start, stop, step, unique = .false._LK)
244change
245"+1", "+5", "+3", "+1", "+1", "+3", "+5", "+3", "+5", "+3", "+3", "+1"
246
247count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
248count
249+5
250change = getChange(count, start, stop, step)
251change
252"+6", "+6", "+9", "+1", "+6"
253
254count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
255count
256+9
257change = getChange(count, start, stop, step, unique = .true._LK)
258change
259"+5", "+1", "-7", "+9", "-3", "-5", "-1", "-9", "+7"
260
261count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
262count
263+12
264change = getChange(count, start, stop, step, unique = .false._LK)
265change
266"+3", "+3", "+5", "+1", "+5", "+5", "+1", "+1", "+5", "+5", "+1", "+1"
267
268count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
269count
270+7
271change = getChange(count, start, stop, step)
272change
273"+0", "+3", "+0", "+2", "+8", "+2", "+4"
274
275count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
276count
277+10
278change = getChange(count, start, stop, step, unique = .true._LK)
279change
280"+5", "-1", "+3", "-9", "+1", "-5", "+7", "-3", "+9", "-7"
281
282count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
283count
284+11
285change = getChange(count, start, stop, step, unique = .false._LK)
286change
287"+5", "+3", "+3", "+5", "+1", "+3", "+3", "+3", "+5", "+1", "+1"
288
289count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
290count
291+9
292change = getChange(count, start, stop, step)
293change
294"+1", "+1", "+1", "+9", "+4", "+9", "+1", "+0", "+5"
295
296count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
297count
298+6
299change = getChange(count, start, stop, step, unique = .true._LK)
300change
301"+9", "-5", "-9", "-3", "-1", "+3"
302
303count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
304count
305+10
306change = getChange(count, start, stop, step, unique = .false._LK)
307change
308"+5", "+5", "+3", "+1", "+1", "+5", "+3", "+5", "+5", "+1"
309
310count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
311count
312+2
313change = getChange(count, start, stop, step)
314change
315"+7", "+2"
316
317count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
318count
319+8
320change = getChange(count, start, stop, step, unique = .true._LK)
321change
322"+9", "-9", "+7", "+3", "-1", "-5", "-3", "+1"
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", "+3", "+5", "+3", "+5", "+3", "+5", "+1", "+1", "+1", "+5", "+1", "+3"
330
331count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
332count
333+7
334change = getChange(count, start, stop, step)
335change
336"+5", "+0", "+3", "+3", "+2", "+4", "+8"
337
338count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
339count
340+5
341change = getChange(count, start, stop, step, unique = .true._LK)
342change
343"-5", "+7", "-9", "-3", "+3"
344
345count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
346count
347+11
348change = getChange(count, start, stop, step, unique = .false._LK)
349change
350"+1", "+1", "+1", "+1", "+5", "+3", "+1", "+3", "+1", "+1", "+5"
351
352count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
353count
354+7
355change = getChange(count, start, stop, step)
356change
357"+3", "+9", "+7", "+7", "+8", "+2", "+0"
358
359count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
360count
361+6
362change = getChange(count, start, stop, step, unique = .true._LK)
363change
364"+5", "+3", "-3", "+1", "+7", "-7"
365
366count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
367count
368+6
369change = getChange(count, start, stop, step, unique = .false._LK)
370change
371"+5", "+5", "+5", "+3", "+5", "+1"
372
373count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
374count
375+8
376change = getChange(count, start, stop, step)
377change
378"+2", "+4", "+8", "+6", "+3", "+6", "+2", "+3"
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", "+1", "+3", "+9", "+5"
386
387count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
388count
389+12
390change = getChange(count, start, stop, step, unique = .false._LK)
391change
392"+3", "+3", "+3", "+1", "+1", "+3", "+3", "+3", "+3", "+1", "+1", "+5"
393
394count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
395count
396+2
397change = getChange(count, start, stop, step)
398change
399"+1", "+3"
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"+5", "-1", "+3", "+1", "+9", "-7", "-5"
407
408count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
409count
410+11
411change = getChange(count, start, stop, step, unique = .false._LK)
412change
413"+1", "+3", "+1", "+1", "+5", "+3", "+3", "+3", "+1", "+3", "+3"
414
415count = getUnifRand(1, 10); start = 0; stop = 9; step = 1
416count
417+4
418change = getChange(count, start, stop, step)
419change
420"+5", "+0", "+3", "+4"
421
422count = getUnifRand(5, 10); start = 9; stop = -9; step = -2
423count
424+8
425change = getChange(count, start, stop, step, unique = .true._LK)
426change
427"+1", "-1", "-3", "+3", "-5", "-7", "+5", "+7"
428
429count = getUnifRand(5, 15); start = 5; stop = 1; step = -2
430count
431+15
432change = getChange(count, start, stop, step, unique = .false._LK)
433change
434"+5", "+1", "+5", "+5", "+1", "+5", "+3", "+1", "+1", "+5", "+1", "+1", "+5", "+3", "+5"
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: