Octopus
distribution_gaussian.F90
Go to the documentation of this file.
1!! Copyright (C) 2024 M. Lueders
2!!
3!! This Source Code Form is subject to the terms of the Mozilla Public
4!! License, v. 2.0. If a copy of the MPL was not distributed with this
5!! file, You can obtain one at https://mozilla.org/MPL/2.0/.
6!!
7#include "global.h"
8
9
12
13 use, intrinsic :: iso_fortran_env
14 use global_oct_m
17
18 implicit none
19
20 private
21 public :: &
23
24
25contains
26
27
29 !
30 function normal_distribution_get_random(seed, n) result(values)
31 integer(int64), intent(inout) :: seed
32 integer, intent(in) :: n
33
34 real(real64) :: values(1:n, 1:2)
35
36 real(real64) :: flat(1:2*n)
37 real(real64) :: R(n), Theta(n)
38
39 call shiftseed(seed, 1000_int64)
40 call quickrnd(seed, 2*n, flat)
41
42 r = sqrt(-2.0_real64 * log(1.0_real64 - flat(1:n)))
43 theta = 2.0_real64 * m_pi * flat(n+1:2*n)
44
45 values(:,1) = r * cos(theta)
46 values(:,2) = r * sin(theta)
47
49
50
double log(double __x) __attribute__((__nothrow__
double sin(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double cos(double __x) __attribute__((__nothrow__
This module provides a random number generator for a normalized gaussian distribution.
real(real64) function, dimension(1:n, 1:2), public normal_distribution_get_random(seed, n)
This function implements the Box Mueller algorithm to produce n pairs of normal distributed random nu...
real(real64), parameter, public m_pi
some mathematical constants
Definition: global.F90:189
subroutine, public shiftseed(iseed, n)
Definition: quickrnd.F90:260