C Library Functions - random_int (3)
NAME
random_int(3f) - [M_random] return an integer between low and high value inclusive
(LICENSE:MIT)
CONTENTS
Synopsis
Description
Options
Returns
Examples
Author
License
SYNOPSIS
function random_int(first,last) result(rand_int)
integer,intent(in) :: first,last
integer :: rand_int
DESCRIPTION
Return an integer uniformly distributed from the set {first,,first+1,...,last-1,last}.
OPTIONS
|
first |
lowest value of range of integer values to randomly return
|
|
last |
highest value of range of integer values to randomly return
|
|
RETURNS
|
rand_int |
| |
a random integer value between FIRST LAST inclusive
|
|
EXAMPLES
Sample program
program demo_random_int
use M_random, only : random_int, init_random_seed_by_system_clock
implicit none
integer :: i
call init_random_seed_by_system_clock()
write(*,(*(i0:,1x)))(random_int(1,10),i=1,20)
write(*,(*(i0:,1x)))(random_int(-5,5),i=1,20)
end program demo_random_int
Sample output
|
|
1 3 |
8 1 2 6 8 7 4 10 7 3 8 3 10 1 5 2 9 8
|
|
4 5 -3 5 2 -5 -4 4 -5 |
| |
-3 -2 -2 -2 -1 -2 4 -2 -2 4 -4
|
|
AUTHOR
John S. Urban
LICENSE
MIT License
| Nemo Release 3.1 | random_int (3) | June 29, 2025 |
Generated by manServer 1.08 from c240f450-1408-4dd9-b963-d7099ba1c465 using man macros.