Skip to content

Commit 8edd7b3

Browse files
committed
Add rand_int
1 parent 4654235 commit 8edd7b3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

fortran/solver/src/random.f90

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module random_mod
44
interface shuffle
55
module procedure shuffle_i1, shuffle_i4
66
end interface shuffle
7-
public :: shuffle
7+
public :: shuffle, rand_int
88
contains
99
subroutine shuffle_i1(arr, n, mask)
1010
integer(1), intent(inout) :: arr(n)
@@ -76,4 +76,10 @@ subroutine shuffle_i4(arr, n, mask)
7676
end if
7777

7878
end subroutine shuffle_i4
79+
integer function rand_int(min, max) result(val)
80+
integer, intent(in):: min, max
81+
real :: r
82+
call random_number(r)
83+
val = floor(min + r * (max - min))
84+
end function rand_int
7985
end module random_mod

0 commit comments

Comments
 (0)