Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Uniform01.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* Uniform01.h (C) 2000-2014 */
9/* */
10/* Randomiser 'Uniform01'. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_RANDOM_UNIFORM01_H
14#define ARCANE_RANDOM_UNIFORM01_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/FatalErrorException.h"
19
20#include "arcane/random/RandomGlobal.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25ARCANE_BEGIN_NAMESPACE
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30RANDOM_BEGIN_NAMESPACE
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*
36 * Copyright Jens Maurer 2000-2001
37 * Permission to use, copy, modify, sell, and distribute this software
38 * is hereby granted without fee provided that the above copyright notice
39 * appears in all copies and that both that copyright notice and this
40 * permission notice appear in supporting documentation,
41 *
42 * Jens Maurer makes no representations about the suitability of this
43 * software for any purpose. It is provided "as is" without express or
44 * implied warranty.
45 *
46 * See http://www.boost.org for most recent version including documentation.
47 *
48 * $Id: Uniform01.h 6199 2005-11-08 13:52:46Z grospelx $
49 *
50 * Revision history
51 * 2001-02-18 moved to individual header files
52 */
53
54// Because it is so commonly used: uniform distribution on the real [0..1)
55// range. This allows for specializations to avoid a costly FP division
64template<class UniformRandomNumberGenerator>
66{
67 public:
69 typedef Real result_type;
70 static const bool has_fixed_range = false;
71
72 explicit Uniform01(base_type & rng)
73 : _rng(rng) { }
74 // compiler-generated copy ctor is fine
75 // assignment is disallowed because there is a reference member
76
79 {
80 return apply(_rng);
81 }
82
87 static Real apply(base_type& _rng)
88 {
89 // Comme _rng() peut retourner 1.0, fait une boucle
90 // permettant de relancer le générateur tant que
91 // la valeur retournée vaut 1.0. Pour éviter
92 // une boucle infinie, effectue au maximum 100 itérations
93 // (la probabilité de tirer 100 fois la valeur 1.0
94 // devrait être quasiment nulle).
95 Real rng_val = _apply(_rng,_rng());
96 for(int x=0;x<100;++x){
97 if (rng_val<1.0)
98 return rng_val;
99 rng_val = _apply(_rng,_rng());
100 }
101 return 1.0-1.0e-10;
102 }
103
112 static ARCANE_DEPRECATED_122 Real apply(const base_type& _rng,typename base_type::result_type rng_val)
113 {
114 Real r = _apply(_rng,rng_val);
115 if (r<1.0)
116 return r;
117 // Retourne un nombre proche de 1 mais inférieur.
118 return (1.0-1.0e-10);
119 }
121 static Real min() { return 0.0; }
123 static Real max() { return 1.0; }
124
125 private:
126
127 static Real _apply(const base_type& _rng,typename base_type::result_type rng_val)
128 {
129 return static_cast<Real>(rng_val - _rng.min()) /
130 (static_cast<Real>(_rng.max()-_rng.min()) +
131 (std::numeric_limits<base_result>::is_integer ? 1.0 : 0.0));
132 }
133
134 private:
135
136 typedef typename base_type::result_type base_result;
137 base_type & _rng;
138};
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143RANDOM_END_NAMESPACE
144
145/*---------------------------------------------------------------------------*/
146/*---------------------------------------------------------------------------*/
147
148ARCANE_END_NAMESPACE
149
150/*---------------------------------------------------------------------------*/
151/*---------------------------------------------------------------------------*/
152
153#endif
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Génère un nombre aléatoire dans l'intervalle [0,1[.
Definition Uniform01.h:66
static Real min()
Valeur minimal retournée.
Definition Uniform01.h:121
Real operator()()
Génère un nombre aléatoire compris dans l'intervalle [0,1[.
Definition Uniform01.h:78
static Real apply(base_type &_rng)
Génère un nombre aléatoire compris dans l'intervalle [0,1[ à partir du générateur _rng.
Definition Uniform01.h:87
static ARCANE_DEPRECATED_122 Real apply(const base_type &_rng, typename base_type::result_type rng_val)
Definition Uniform01.h:112
static Real max()
Borne supérieure (non atteinte) des valeurs retournées.
Definition Uniform01.h:123