Code Duplication    Length = 18-19 lines in 3 locations

src/Samsara/Fermat/Provider/Distribution/Exponential.php 1 location

@@ 156-174 (lines=19) @@
153
     * @return ImmutableNumber
154
     * @throws OptionalExit
155
     */
156
    public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableNumber
157
    {
158
159
        $i = 0;
160
161
        do {
162
            $randomNumber = $this->random();
163
            $i++;
164
        } while (($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) && $i < $maxIterations);
165
166
        if ($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) {
167
            throw new OptionalExit(
168
                'All random numbers generated were outside of the requested range',
169
                'A suitable random number, restricted by the $max ('.$max.') and $min ('.$min.'), could not be found within '.$maxIterations.' iterations'
170
            );
171
        }
172
173
        return $randomNumber;
174
    }
175
176
}

src/Samsara/Fermat/Provider/Distribution/Normal.php 1 location

@@ 227-244 (lines=18) @@
224
     * @throws OptionalExit
225
     * @throws IntegrityConstraint
226
     */
227
    public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableNumber
228
    {
229
        $i = 0;
230
231
        do {
232
            $randomNumber = $this->random();
233
            $i++;
234
        } while (($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) && $i < $maxIterations);
235
236
        if ($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) {
237
            throw new OptionalExit(
238
                'All random numbers generated were outside of the requested range',
239
                'A suitable random number, restricted by the $max ('.$max.') and $min ('.$min.'), could not be found within '.$maxIterations.' iterations'
240
            );
241
        }
242
243
        return $randomNumber;
244
    }
245
246
}

src/Samsara/Fermat/Provider/Distribution/Poisson.php 1 location

@@ 180-197 (lines=18) @@
177
     * @throws OptionalExit
178
     * @return ImmutableNumber
179
     */
180
    public function rangeRandom($min = 0, $max = PHP_INT_MAX, int $maxIterations = 20): ImmutableNumber
181
    {
182
        $i = 0;
183
184
        do {
185
            $randomNumber = $this->random();
186
            $i++;
187
        } while (($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) && $i < $maxIterations);
188
189
        if ($randomNumber->isGreaterThan($max) || $randomNumber->isLessThan($min)) {
190
            throw new OptionalExit(
191
                'All random numbers generated were outside of the requested range',
192
                'A suitable random number, restricted by the $max ('.$max.') and $min ('.$min.'), could not be found within '.$maxIterations.' iterations'
193
            );
194
        } else {
195
            return $randomNumber;
196
        }
197
    }
198
199
    /**
200
     * Method PA from The Computer Generation of Poisson Random Variables by A. C. Atkinson, 1979