FMS 2025.01-dev
Flexible Modeling System
Loading...
Searching...
No Matches
random_numbers.inc
1!***********************************************************************
2!* GNU Lesser General Public License
3!*
4!* This file is part of the GFDL Flexible Modeling System (FMS).
5!*
6!* FMS is free software: you can redistribute it and/or modify it under
7!* the terms of the GNU Lesser General Public License as published by
8!* the Free Software Foundation, either version 3 of the License, or (at
9!* your option) any later version.
10!*
11!* FMS is distributed in the hope that it will be useful, but WITHOUT
12!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14!* for more details.
15!*
16!* You should have received a copy of the GNU Lesser General Public
17!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
18!***********************************************************************
19
20 !> Draws random scalar
21 subroutine get_random_number_0d_(stream, number)
22 type(randomNumberStream), intent(inout) :: stream
23 real(FMS_RN_KIND_), intent( out) :: number
24
25 number = real(getrandomreal(stream%theNumbers), fms_rn_kind_)
26 end subroutine
27
28 !> Draws random 1D array
29 subroutine get_random_number_1d_(stream, numbers)
30 type(randomNumberStream), intent(inout) :: stream
31 real(FMS_RN_KIND_), dimension(:), intent( out) :: numbers
32
33 ! Local variables
34 integer :: i
35
36 do i = 1, size(numbers)
37 call get_random_number_0d_(stream, numbers(i))
38 end do
39 end subroutine
40
41 !> Draws random 2D array
42 subroutine get_random_number_2d_(stream, numbers)
43 type(randomNumberStream), intent(inout) :: stream
44 real(FMS_RN_KIND_), dimension(:, :), intent( out) :: numbers
45
46 ! Local variables
47 integer :: i
48
49 do i = 1, size(numbers, 2)
50 call get_random_number_1d_(stream, numbers(:, i))
51 end do
52 end subroutine