ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
random.h
Go to the documentation of this file.
1#ifndef RANDOM_H
2#define RANDOM_H
3#include <cstdlib>
4#include <cassert>
5
6namespace ModuleBase
7{
8
9class Random
10{
11 public:
14
15 static void between0and1( double *v, const int &num )
16 {
17 assert( v!= NULL);
18 assert( num > 1);
19 for(int i=0; i<num; i++)
20 {
21 v[i] = static_cast<double>( std::rand() ) / RAND_MAX;
22 }
23 }
24
25 static double betweenMinus2and2(void)
26 {
27 return 2.0*betweenMinus1and1();
28 }
29
30 static double betweenMinus1and1(void)
31 {
32 const int a = std::rand() % 2;
33 if(a==0) return between0and1();
34 else if(a==1) return betweenMinus1and0();
35 else throw(std::string(__FILE__)+" line "+std::to_string(__LINE__)); // Peize Lin add to fix warning 2019-05-01
36 }
37
38 static double between0and1(void)
39 {
40 return static_cast<double>( std::rand() )/RAND_MAX;
41 }
42
43 static double betweenMinus1and0(void)
44 {
45 return -static_cast<double>( std::rand() )/RAND_MAX;
46 }
47
48};
49
50}
51
52#endif
Definition random.h:10
static double betweenMinus2and2(void)
Definition random.h:25
static void between0and1(double *v, const int &num)
Definition random.h:15
static double betweenMinus1and1(void)
Definition random.h:30
static double betweenMinus1and0(void)
Definition random.h:43
static double between0and1(void)
Definition random.h:38
Definition array_pool.h:6