FMS  2025.04
Flexible Modeling System
random_numbers.inc
1 !***********************************************************************
2 !* Apache License 2.0
3 !*
4 !* This file is part of the GFDL Flexible Modeling System (FMS).
5 !*
6 !* Licensed under the Apache License, Version 2.0 (the "License");
7 !* you may not use this file except in compliance with the License.
8 !* You may obtain a copy of the License at
9 !*
10 !* http://www.apache.org/licenses/LICENSE-2.0
11 !*
12 !* FMS is distributed in the hope that it will be useful, but WITHOUT
13 !* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied;
14 !* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 !* PARTICULAR PURPOSE. See the License for the specific language
16 !* governing permissions and limitations under the License.
17 !***********************************************************************
18 
19  !> Draws random scalar
20  subroutine get_random_number_0d_(stream, number)
21  type(randomNumberStream), intent(inout) :: stream
22  real(FMS_RN_KIND_), intent( out) :: number
23 
24  number = real(getrandomreal(stream%theNumbers), fms_rn_kind_)
25  end subroutine
26 
27  !> Draws random 1D array
28  subroutine get_random_number_1d_(stream, numbers)
29  type(randomNumberStream), intent(inout) :: stream
30  real(FMS_RN_KIND_), dimension(:), intent( out) :: numbers
31 
32  ! Local variables
33  integer :: i
34 
35  do i = 1, size(numbers)
36  call get_random_number_0d_(stream, numbers(i))
37  end do
38  end subroutine
39 
40  !> Draws random 2D array
41  subroutine get_random_number_2d_(stream, numbers)
42  type(randomNumberStream), intent(inout) :: stream
43  real(FMS_RN_KIND_), dimension(:, :), intent( out) :: numbers
44 
45  ! Local variables
46  integer :: i
47 
48  do i = 1, size(numbers, 2)
49  call get_random_number_1d_(stream, numbers(:, i))
50  end do
51  end subroutine