cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cmnRandomSequence.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ofri Sadowsky, Anton Deguet
7  Created on: 2003-06-09
8 
9  (C) Copyright 2003-2013 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 
27 #pragma once
28 
29 #ifndef _cmnRandomSequence_h
30 #define _cmnRandomSequence_h
31 
33 
34 #include <stdlib.h>
35 #include <cstddef>
36 
37 #include <cisstCommon/cmnExport.h>
38 
67 {
68 public:
71  typedef unsigned int SeedType;
72 
76 
79  typedef unsigned long SequenceCounterType;
80 
83  static const SeedType DefaultSeed;
84 
88 
92 
93 protected:
99  SetSeed(DefaultSeed);
100  }
101 
106  cmnRandomSequence(const SeedType seed, const SequenceCounterType position = 0) {
107  SetSeed(seed);
108  SetSequencePosition(position);
109  }
110 
116  SetSeed(other.GetSeed());
117  SetSequencePosition(other.GetSequencePosition());
118  }
119 
124  SetSeed(other.GetSeed());
125  SetSequencePosition(other.GetSequencePosition());
126  return *this;
127  }
128 
133 
134 public:
139  return RandomInstance;
140  }
141 
145  SeedType GetSeed(void) const {
146  return Seed;
147  }
148 
152  void SetSeed(const SeedType seed) {
153  Seed = seed;
154  SequencePosition = 0;
155  srand(Seed);
156  }
157 
162  return SequencePosition;
163  }
164 
170  SetSeed(GetSeed());
171  while (GetSequencePosition() < position) {
172  ExtractRandomElement();
173  }
174  }
175 
176 
181  ++SequencePosition;
182  return rand();
183  }
184 
186 
189  template <typename _valueType>
190  void ExtractRandomValue(_valueType & result);
191 
192  template <typename _valueType>
193  inline void ExtractRandomValue(const _valueType min, const _valueType max, _valueType & result);
194 
195  template <typename _valueType>
196  inline void ExtractRandomValueArray(const _valueType min, const _valueType max, _valueType * array,
197  const size_t arraySize);
199 
201  float ExtractRandomFloat(void) {
202  ElementaryRandomNumber randomNumber = ExtractRandomElement();
203  float myPosition = static_cast<float>(randomNumber) - static_cast<float>(LowerRandomBound);
204  float randomFloat = myPosition / (static_cast<float>(UpperRandomBound) - static_cast<float>(LowerRandomBound) + 1);
205  return randomFloat;
206  }
208  float ExtractRandomFloat(const float min, const float max) {
209  const float randomFloat = ExtractRandomFloat();
210  return (randomFloat * (max - min)) + min;
211  }
212  void ExtractRandomFloatArray(const float min, const float max, float * array,
213  const size_t arraySize) {
214  for (size_t i = 0; i < arraySize; ++i, ++array) {
215  *array = ExtractRandomFloat(min, max);
216  }
217  }
218 
220  double ExtractRandomDouble(void) {
221  return (static_cast<double>(ExtractRandomElement()) - static_cast<double>(LowerRandomBound)) / (static_cast<double>(UpperRandomBound) - static_cast<double>(LowerRandomBound) + 1);
222  }
224  double ExtractRandomDouble(const double min, const double max) {
225  const double randomDouble = ExtractRandomDouble();
226  return (randomDouble * (max - min)) + min;
227  }
228  void ExtractRandomDoubleArray(const double min, const double max, double *array,
229  const size_t arraySize) {
230  for (size_t i = 0; i < arraySize; ++i, ++array) {
231  *array = ExtractRandomDouble(min, max);
232  }
233  }
234 
235  int ExtractRandomInt(void) {
236  return ExtractRandomElement();
237  }
238  int ExtractRandomInt(const int min, const int max) {
239  const float randomFloat = ExtractRandomFloat();
240  return static_cast<int>((randomFloat * (max - min)) + min); }
241 
242  void ExtractRandomIntArray(const int min, const int max, int *array,
243  const size_t arraySize) {
244  for (size_t i = 0; i < arraySize; ++i, ++array) {
245  *array = ExtractRandomInt(min, max);
246  }
247  }
248 
249  unsigned int ExtractRandomUnsignedInt(void) {
250  int randomInt = ExtractRandomElement();
251  return static_cast<unsigned int>(randomInt);
252  }
253  unsigned int ExtractRandomUnsignedInt(const unsigned int min, const unsigned int max) {
254  const float randomFloat = ExtractRandomFloat();
255  return static_cast<unsigned int>((randomFloat * (max - min)) + min);
256  }
257  void ExtractRandomUnsignedIntArray(const unsigned int min, const unsigned int max, unsigned int *array,
258  const size_t arraySize) {
259  for (size_t i = 0; i < arraySize; ++i, ++array) {
260  *array = ExtractRandomUnsignedInt(min, max);
261  }
262  }
263 
264  short ExtractRandomShort(void) {
265  return static_cast<short>(ExtractRandomElement()&0xffff);
266  }
267  short ExtractRandomShort(const short min, const short max) {
268  const float randomFloat = ExtractRandomFloat();
269  return static_cast<short>((randomFloat * (max - min)) + min);
270  }
271  void ExtractRandomShortArray(const short min, const short max, short *array,
272  const size_t arraySize) {
273  for (size_t i = 0; i < arraySize; ++i, ++array) {
274  *array = ExtractRandomShort(min, max);
275  }
276  }
277 
278  unsigned short ExtractRandomUnsignedShort(void) {
279  int randomInt = ExtractRandomElement();
280  return static_cast<unsigned short>((0xff) & randomInt);
281  }
282  unsigned short ExtractRandomUnsignedShort(const unsigned short min, const unsigned short max) {
283  const float randomFloat = ExtractRandomFloat();
284  return static_cast<unsigned short>((randomFloat * (max - min)) + min);
285  }
286  void ExtractRandomUnsignedShortArray(const unsigned short min, const unsigned short max, unsigned short *array,
287  const size_t arraySize) {
288  for (size_t i = 0; i < arraySize; ++i, ++array) {
289  *array = ExtractRandomUnsignedShort(min, max);
290  }
291  }
292 
293  inline long ExtractRandomLong(void) {
294 #if (CISST_DATA_MODEL == CISST_LP64)
295  // long are 64 bits so we can cast from long long
296  return ExtractRandomLongLong();
297 #else
298  // long are 32 bits so we can cast from int
299  return ExtractRandomInt();
300 #endif
301  }
302  inline long ExtractRandomLong(const long min, const long max) {
303  const float randomFloat = ExtractRandomFloat();
304  return static_cast<long>((randomFloat * (max - min)) + min);
305  }
306  inline void ExtractRandomLongArray(const long min, const long max, long * array,
307  const size_t arraySize) {
308  for (size_t i = 0; i < arraySize; ++i, ++array)
309  *array = ExtractRandomLong(min, max);
310  }
311 
312  inline unsigned long ExtractRandomUnsignedLong(void) {
313 #if (CISST_DATA_MODEL == CISST_LP64)
314  // long are 64 bits so we can cast from long long
315  return ExtractRandomUnsignedLongLong();
316 #else
317  // long are 32 bits so we can cast from int
318  return ExtractRandomUnsignedInt();
319 #endif
320 
321  }
322  inline unsigned long ExtractRandomUnsignedLong(const unsigned long min, const unsigned long max) {
323  const double randomDouble = ExtractRandomDouble();
324  return static_cast<unsigned long >((randomDouble * (max - min)) + min);
325  }
326  inline void ExtractRandomUnsignedLongArray(const unsigned long min, const unsigned long max, unsigned long * array,
327  const size_t arraySize) {
328  for (size_t i = 0; i < arraySize; ++i, ++array) {
329  *array = ExtractRandomUnsignedLong(min, max);
330  }
331  }
332 
333  inline long long ExtractRandomLongLong(void) {
334  // create 64 random bits
335  long long int result;
336  int * part = reinterpret_cast<int *>(&result);
337  *part = ExtractRandomElement();
338  part++;
339  *part = ExtractRandomElement();
340  return result;
341 
342  }
343  inline long ExtractRandomLongLong(const long long min, const long long max) {
344  const float randomFloat = ExtractRandomFloat();
345  return static_cast<long long>((randomFloat * (max - min)) + min);
346  }
347  inline void ExtractRandomLongLongArray(const long long min, const long long max, long long * array,
348  const size_t arraySize) {
349  for (size_t i = 0; i < arraySize; ++i, ++array) {
350  *array = ExtractRandomLongLong(min, max);
351  }
352  }
353 
354  inline unsigned long long ExtractRandomUnsignedLongLong(void) {
355  // create 64 random bits
356  unsigned long long int result;
357  int * part = reinterpret_cast<int *>(&result);
358  *part = ExtractRandomElement();
359  part++;
360  *part = ExtractRandomElement();
361  return result;
362  }
363  inline unsigned long long ExtractRandomUnsignedLongLong(const unsigned long long min, const unsigned long long max) {
364  const double randomDouble = ExtractRandomDouble();
365  return static_cast<unsigned long long >((randomDouble * (max - min)) + min);
366  }
367  inline void ExtractRandomUnsignedLongLongArray(const unsigned long long min, const unsigned long long max, unsigned long long * array,
368  const size_t arraySize) {
369  for (size_t i = 0; i < arraySize; ++i, ++array) {
370  *array = ExtractRandomUnsignedLongLong(min, max);
371  }
372  }
373 
374  char ExtractRandomChar(void) {
375  int randomInt = ExtractRandomElement();
376  return static_cast<char>((0xff) & randomInt);
377  }
378  char ExtractRandomChar(const char min, const char max) {
379  const float randomFloat = ExtractRandomFloat();
380  return static_cast<char>((randomFloat * (max - min)) + min);
381  }
382  void ExtractRandomCharArray(const char min, const char max, char *array,
383  const size_t arraySize) {
384  for (size_t i = 0; i < arraySize; ++i, ++array) {
385  *array = ExtractRandomChar(min, max);
386  }
387  }
388 
389  unsigned char ExtractRandomUnsignedChar(void) {
390  int randomInt = ExtractRandomElement();
391  return static_cast<unsigned char>((0xff) & randomInt);
392  }
393  unsigned char ExtractRandomUnsignedChar(const unsigned char min, const unsigned char max) {
394  const float randomFloat = ExtractRandomFloat();
395  return static_cast<unsigned char>((randomFloat * (max - min)) + min);
396  }
397  void ExtractRandomUnsignedCharArray(const unsigned char min, const unsigned char max, unsigned char *array,
398  const size_t arraySize) {
399  for (size_t i = 0; i < arraySize; ++i, ++array) {
400  *array = ExtractRandomUnsignedChar(min, max);
401  }
402  }
403 
405  void ExtractRandomPermutation(const size_t length, size_t * array);
406 
415  size_t ExtractRandomSizeT(const size_t min, const size_t max) {
416  const float randomFloat = ExtractRandomFloat();
417  return static_cast<size_t>((randomFloat * (max - min)) + min);
418  }
419  void ExtractRandomSizeTArray(const size_t min, const size_t max, size_t * array,
420  const size_t arraySize) {
421  for (size_t i = 0; i < arraySize; ++i, ++array) {
422  *array = ExtractRandomSizeT(min, max);
423  }
424  }
425 
426  ptrdiff_t ExtractRandomPtrdiffT(const ptrdiff_t min, const ptrdiff_t max) {
427  const float randomFloat = ExtractRandomFloat();
428  return static_cast<ptrdiff_t>((randomFloat * (max - min)) + min);
429  }
430  void ExtractRandomPtrdiffTArray(const ptrdiff_t min, const ptrdiff_t max, ptrdiff_t * array,
431  const size_t arraySize) {
432  for (size_t i = 0; i < arraySize; ++i, ++array) {
433  *array = ExtractRandomPtrdiffT(min, max);
434  }
435  }
437 
438 private:
441  SeedType Seed;
442 
445  SequenceCounterType SequencePosition;
446 
447 };
448 
449 
450 /* Specializations of cmnRandomSequence::ExtractRandomValue */
451 #ifndef DOXYGEN
452 /* --- float --- */
454 void cmnRandomSequence::ExtractRandomValue<float>(float & result);
456 void cmnRandomSequence::ExtractRandomValue<float>(const float min, const float max, float & result);
458 void cmnRandomSequence::ExtractRandomValueArray<float>(const float min, const float max, float * array,
459  const size_t arraySize);
460 
461 /* --- double --- */
463 void cmnRandomSequence::ExtractRandomValue<double>(double & result);
465 void cmnRandomSequence::ExtractRandomValue<double>(const double min, const double max, double & result);
467 void cmnRandomSequence::ExtractRandomValueArray<double>(const double min, const double max, double * array,
468  const size_t arraySize);
469 
470 /* --- int --- */
472 void cmnRandomSequence::ExtractRandomValue<int>(int & result);
474 void cmnRandomSequence::ExtractRandomValue<int>(const int min, const int max, int & result);
476 void cmnRandomSequence::ExtractRandomValueArray<int>(const int min, const int max, int * array,
477  const size_t arraySize);
478 /* --- unsigned int --- */
480 void cmnRandomSequence::ExtractRandomValue<unsigned int>(unsigned int & result);
482 void cmnRandomSequence::ExtractRandomValue<unsigned int>(const unsigned int min, const unsigned int max, unsigned int & result);
484 void cmnRandomSequence::ExtractRandomValueArray<unsigned int>(const unsigned int min, const unsigned int max, unsigned int * array,
485  const size_t arraySize);
486 
487 /* --- short --- */
489 void cmnRandomSequence::ExtractRandomValue<short>(short & result);
491 void cmnRandomSequence::ExtractRandomValue<short>(const short min, const short max, short & result);
493 void cmnRandomSequence::ExtractRandomValueArray<short>(const short min, const short max, short * array,
494  const size_t arraySize);
495 /* --- unsigned short --- */
497 void cmnRandomSequence::ExtractRandomValue<unsigned short>(unsigned short & result);
499 void cmnRandomSequence::ExtractRandomValue<unsigned short>(const unsigned short min, const unsigned short max, unsigned short & result);
501 void cmnRandomSequence::ExtractRandomValueArray<unsigned short>(const unsigned short min, const unsigned short max, unsigned short * array,
502  const size_t arraySize);
503 
504 /* --- long --- */
506 void cmnRandomSequence::ExtractRandomValue<long>(long & result);
508 void cmnRandomSequence::ExtractRandomValue<long>(const long min, const long max, long & result);
510 void cmnRandomSequence::ExtractRandomValueArray<long>(const long min, const long max, long * array,
511  const size_t arraySize);
512 
513 /* --- unsigned long --- */
515 void cmnRandomSequence::ExtractRandomValue<unsigned long>(unsigned long & result);
517 void cmnRandomSequence::ExtractRandomValue<unsigned long>(const unsigned long min, const unsigned long max, unsigned long & result);
519 void cmnRandomSequence::ExtractRandomValueArray<unsigned long>(const unsigned long min, const unsigned long max, unsigned long * array,
520  const size_t arraySize);
521 
522 /* --- long long --- */
524 void cmnRandomSequence::ExtractRandomValue<long long>(long long & result);
526 void cmnRandomSequence::ExtractRandomValue<long long>(const long long min, const long long max, long long & result);
528 void cmnRandomSequence::ExtractRandomValueArray<long long>(const long long min, const long long max, long long * array,
529  const size_t arraySize);
530 
531 /* --- unsigned long long --- */
533 void cmnRandomSequence::ExtractRandomValue<unsigned long long>(unsigned long long & result);
535 void cmnRandomSequence::ExtractRandomValue<unsigned long long>(const unsigned long long min, const unsigned long long max, unsigned long long & result);
537 void cmnRandomSequence::ExtractRandomValueArray<unsigned long long>(const unsigned long long min, const unsigned long long max, unsigned long long * array,
538  const size_t arraySize);
539 
540 /* --- char --- */
542 void cmnRandomSequence::ExtractRandomValue<char>(char & result);
544 void cmnRandomSequence::ExtractRandomValue<char>(const char min, const char max, char & result);
546 void cmnRandomSequence::ExtractRandomValueArray<char>(const char min, const char max, char * array,
547  const size_t arraySize);
548 
549 /* --- unsigned char --- */
551 void cmnRandomSequence::ExtractRandomValue<unsigned char>(unsigned char & result);
553 void cmnRandomSequence::ExtractRandomValue<unsigned char>(const unsigned char min, const unsigned char max, unsigned char & result);
555 void cmnRandomSequence::ExtractRandomValueArray<unsigned char>(const unsigned char min, const unsigned char max, unsigned char * array,
556  const size_t arraySize);
557 
558 /* --- bool --- */
560 void cmnRandomSequence::ExtractRandomValue<bool>(bool & result);
562 void cmnRandomSequence::ExtractRandomValue<bool>(const bool min, const bool max, bool & result);
564 void cmnRandomSequence::ExtractRandomValueArray<bool>(const bool min, const bool max, bool * array,
565  const size_t arraySize);
566 
567 
568 /* --- float ---*/
570 inline void cmnRandomSequence::ExtractRandomValue(float & result) {
571  result = ExtractRandomFloat();
572 }
574 inline void cmnRandomSequence::ExtractRandomValue(const float min, const float max, float & result) {
575  result = ExtractRandomFloat(min, max);
576 }
578 inline void cmnRandomSequence::ExtractRandomValueArray(const float min, const float max, float * array,
579  const size_t arraySize) {
580  ExtractRandomFloatArray(min, max, array, arraySize);
581 }
582 
583 /* --- double ---*/
585 inline void cmnRandomSequence::ExtractRandomValue(double & result) {
586  result = ExtractRandomDouble();
587 }
589 inline void cmnRandomSequence::ExtractRandomValue(const double min, const double max, double & result) {
590  result = ExtractRandomDouble(min, max);
591 }
593 inline void cmnRandomSequence::ExtractRandomValueArray(const double min, const double max, double * array,
594  const size_t arraySize) {
595  ExtractRandomDoubleArray(min, max, array, arraySize);
596 }
597 
598 /* --- int ---*/
600 inline void cmnRandomSequence::ExtractRandomValue(int & result) {
601  result = ExtractRandomInt();
602 }
604 inline void cmnRandomSequence::ExtractRandomValue(const int min, const int max, int & result) {
605  result = ExtractRandomInt(min, max);
606 }
608 inline void cmnRandomSequence::ExtractRandomValueArray(const int min, const int max, int * array,
609  const size_t arraySize) {
610  ExtractRandomIntArray(min, max, array, arraySize);
611 }
612 /* --- unsigned int ---*/
614 inline void cmnRandomSequence::ExtractRandomValue(unsigned int & result) {
615  result = ExtractRandomUnsignedInt();
616 }
618 inline void cmnRandomSequence::ExtractRandomValue(const unsigned int min, const unsigned int max, unsigned int & result) {
619  result = ExtractRandomUnsignedInt(min, max);
620 }
622 inline void cmnRandomSequence::ExtractRandomValueArray(const unsigned int min, const unsigned int max, unsigned int * array,
623  const size_t arraySize) {
624  ExtractRandomUnsignedIntArray(min, max, array, arraySize);
625 }
626 
627 /* --- long ---*/
629 inline void cmnRandomSequence::ExtractRandomValue(long & result) {
630  result = ExtractRandomLong();
631 }
633 inline void cmnRandomSequence::ExtractRandomValue(const long min, const long max, long & result) {
634  result = ExtractRandomLong(min, max);
635 }
637 inline void cmnRandomSequence::ExtractRandomValueArray(const long min, const long max, long * array,
638  const size_t arraySize) {
639  ExtractRandomLongArray(min, max, array, arraySize);
640 }
641 /* --- unsigned long ---*/
643 inline void cmnRandomSequence::ExtractRandomValue(unsigned long & result) {
644  result = ExtractRandomUnsignedLong();
645 }
647 inline void cmnRandomSequence::ExtractRandomValue(const unsigned long min, const unsigned long max, unsigned long & result) {
648  result = ExtractRandomUnsignedLong(min, max);
649 }
651 inline void cmnRandomSequence::ExtractRandomValueArray(const unsigned long min, const unsigned long max, unsigned long * array,
652  const size_t arraySize) {
653  ExtractRandomUnsignedLongArray(min, max, array, arraySize);
654 }
655 
656 /* --- long long ---*/
658 inline void cmnRandomSequence::ExtractRandomValue(long long & result) {
659  result = ExtractRandomLongLong();
660 }
662 inline void cmnRandomSequence::ExtractRandomValue(const long long min, const long long max, long long & result) {
663  result = ExtractRandomLongLong(min, max);
664 }
666 inline void cmnRandomSequence::ExtractRandomValueArray(const long long min, const long long max, long long * array,
667  const size_t arraySize) {
668  ExtractRandomLongLongArray(min, max, array, arraySize);
669 }
670 /* --- unsigned long long ---*/
672 inline void cmnRandomSequence::ExtractRandomValue(unsigned long long & result) {
674 }
676 inline void cmnRandomSequence::ExtractRandomValue(const unsigned long long min, const unsigned long long max, unsigned long long & result) {
677  result = ExtractRandomUnsignedLongLong(min, max);
678 }
680 inline void cmnRandomSequence::ExtractRandomValueArray(const unsigned long long min, const unsigned long long max, unsigned long long * array,
681  const size_t arraySize) {
682  ExtractRandomUnsignedLongLongArray(min, max, array, arraySize);
683 }
684 
685 
686 /* --- short ---*/
688 inline void cmnRandomSequence::ExtractRandomValue(short & result) {
689  result = ExtractRandomShort();
690 }
692 inline void cmnRandomSequence::ExtractRandomValue(const short min, const short max, short & result) {
693  result = ExtractRandomShort(min, max);
694 }
696 inline void cmnRandomSequence::ExtractRandomValueArray(const short min, const short max, short * array,
697  const size_t arraySize) {
698  ExtractRandomShortArray(min, max, array, arraySize);
699 }
700 /* --- unsigned short ---*/
702 inline void cmnRandomSequence::ExtractRandomValue(unsigned short & result) {
703  result = ExtractRandomUnsignedShort();
704 }
706 inline void cmnRandomSequence::ExtractRandomValue(const unsigned short min, const unsigned short max, unsigned short & result) {
707  result = ExtractRandomUnsignedShort(min, max);
708 }
710 inline void cmnRandomSequence::ExtractRandomValueArray(const unsigned short min, const unsigned short max, unsigned short * array,
711  const size_t arraySize) {
712  ExtractRandomUnsignedShortArray(min, max, array, arraySize);
713 }
714 
715 /* --- char --- */
717 inline void cmnRandomSequence::ExtractRandomValue(char & result) {
718  result = ExtractRandomChar();
719 }
721 inline void cmnRandomSequence::ExtractRandomValue(const char min, const char max, char & result) {
722  result = ExtractRandomChar(min, max);
723 }
725 inline void cmnRandomSequence::ExtractRandomValueArray(const char min, const char max, char * array, const size_t arraySize) {
726  ExtractRandomCharArray(min, max, array, arraySize);
727 }
728 /* --- unsigned char --- */
730 inline void cmnRandomSequence::ExtractRandomValue(unsigned char & result) {
731  result = ExtractRandomUnsignedChar();
732 }
734 inline void cmnRandomSequence::ExtractRandomValue(const unsigned char min, const unsigned char max, unsigned char & result) {
735  result = ExtractRandomUnsignedChar(min, max);
736 }
738 inline void cmnRandomSequence::ExtractRandomValueArray(const unsigned char min, const unsigned char max, unsigned char * array,
739  const size_t arraySize) {
740  ExtractRandomUnsignedCharArray(min, max, array, arraySize);
741 }
742 
743 /* --- bool --- */
745 inline void cmnRandomSequence::ExtractRandomValue(bool & result) {
746  int value = ExtractRandomInt(0, 1024);
747  result = value & 1;
748 }
750 inline void cmnRandomSequence::ExtractRandomValue(const bool min, const bool max, bool & result) {
751  if (min == max) {
752  result = min;
753  } else {
754  ExtractRandomValue(result);
755  }
756 }
758 inline void cmnRandomSequence::ExtractRandomValueArray(const bool min, const bool max, bool * array,
759  const size_t arraySize) {
760  for (size_t i = 0; i < arraySize; ++i, ++array) {
761  ExtractRandomValue(min, max, *array);
762  }
763 }
764 
765 #endif // DOXYGEN
766 
767 #endif // _cmnRandomSequence_h
size_t ExtractRandomSizeT(const size_t min, const size_t max)
Definition: cmnRandomSequence.h:415
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
short ExtractRandomShort(const short min, const short max)
Definition: cmnRandomSequence.h:267
long ExtractRandomLong(void)
Definition: cmnRandomSequence.h:293
void ExtractRandomValueArray(const _valueType min, const _valueType max, _valueType *array, const size_t arraySize)
Definition: cmnRandomSequence.h:578
cmnRandomSequence(const SeedType seed, const SequenceCounterType position=0)
Definition: cmnRandomSequence.h:106
Portability across compilers and operating systems tools.
void ExtractRandomUnsignedShortArray(const unsigned short min, const unsigned short max, unsigned short *array, const size_t arraySize)
Definition: cmnRandomSequence.h:286
unsigned short ExtractRandomUnsignedShort(void)
Definition: cmnRandomSequence.h:278
unsigned int ExtractRandomUnsignedInt(void)
Definition: cmnRandomSequence.h:249
void ExtractRandomDoubleArray(const double min, const double max, double *array, const size_t arraySize)
Definition: cmnRandomSequence.h:228
unsigned char ExtractRandomUnsignedChar(void)
Definition: cmnRandomSequence.h:389
ptrdiff_t ExtractRandomPtrdiffT(const ptrdiff_t min, const ptrdiff_t max)
Definition: cmnRandomSequence.h:426
short ExtractRandomShort(void)
Definition: cmnRandomSequence.h:264
void ExtractRandomUnsignedLongLongArray(const unsigned long long min, const unsigned long long max, unsigned long long *array, const size_t arraySize)
Definition: cmnRandomSequence.h:367
void ExtractRandomCharArray(const char min, const char max, char *array, const size_t arraySize)
Definition: cmnRandomSequence.h:382
void ExtractRandomValue(_valueType &result)
void ExtractRandomLongArray(const long min, const long max, long *array, const size_t arraySize)
Definition: cmnRandomSequence.h:306
void ExtractRandomSizeTArray(const size_t min, const size_t max, size_t *array, const size_t arraySize)
Definition: cmnRandomSequence.h:419
static cmnRandomSequence & GetInstance(void)
Definition: cmnRandomSequence.h:138
int ExtractRandomInt(const int min, const int max)
Definition: cmnRandomSequence.h:238
void ExtractRandomUnsignedIntArray(const unsigned int min, const unsigned int max, unsigned int *array, const size_t arraySize)
Definition: cmnRandomSequence.h:257
long long ExtractRandomLongLong(void)
Definition: cmnRandomSequence.h:333
cmnRandomSequence(const cmnRandomSequence &other)
Definition: cmnRandomSequence.h:115
cmnRandomSequence()
Definition: cmnRandomSequence.h:98
Macros to export the symbols of cisstCommon (in a Dll).
void ExtractRandomIntArray(const int min, const int max, int *array, const size_t arraySize)
Definition: cmnRandomSequence.h:242
void ExtractRandomShortArray(const short min, const short max, short *array, const size_t arraySize)
Definition: cmnRandomSequence.h:271
void ExtractRandomUnsignedLongArray(const unsigned long min, const unsigned long max, unsigned long *array, const size_t arraySize)
Definition: cmnRandomSequence.h:326
float ExtractRandomFloat(const float min, const float max)
Definition: cmnRandomSequence.h:208
double ExtractRandomDouble(const double min, const double max)
Definition: cmnRandomSequence.h:224
unsigned char ExtractRandomUnsignedChar(const unsigned char min, const unsigned char max)
Definition: cmnRandomSequence.h:393
ElementaryRandomNumber ExtractRandomElement(void)
Definition: cmnRandomSequence.h:180
unsigned long SequenceCounterType
Definition: cmnRandomSequence.h:79
SequenceCounterType GetSequencePosition(void) const
Definition: cmnRandomSequence.h:161
static const ElementaryRandomNumber UpperRandomBound
Definition: cmnRandomSequence.h:91
unsigned long long ExtractRandomUnsignedLongLong(void)
Definition: cmnRandomSequence.h:354
unsigned long long ExtractRandomUnsignedLongLong(const unsigned long long min, const unsigned long long max)
Definition: cmnRandomSequence.h:363
unsigned short ExtractRandomUnsignedShort(const unsigned short min, const unsigned short max)
Definition: cmnRandomSequence.h:282
static const ElementaryRandomNumber LowerRandomBound
Definition: cmnRandomSequence.h:87
char ExtractRandomChar(const char min, const char max)
Definition: cmnRandomSequence.h:378
unsigned int SeedType
Definition: cmnRandomSequence.h:71
void ExtractRandomUnsignedCharArray(const unsigned char min, const unsigned char max, unsigned char *array, const size_t arraySize)
Definition: cmnRandomSequence.h:397
#define CISST_DECLARE_TEMPLATE_FUNCTION_SPECIALIZATION
Definition: cmnPortability.h:450
static const SeedType DefaultSeed
Definition: cmnRandomSequence.h:83
SeedType GetSeed(void) const
Definition: cmnRandomSequence.h:145
#define CISST_DEFINE_TEMPLATE_FUNCTION_SPECIALIZATION
Definition: cmnPortability.h:451
long ExtractRandomLongLong(const long long min, const long long max)
Definition: cmnRandomSequence.h:343
cmnRandomSequence & operator=(const cmnRandomSequence &other)
Definition: cmnRandomSequence.h:123
static cmnRandomSequence RandomInstance
Definition: cmnRandomSequence.h:132
int ElementaryRandomNumber
Definition: cmnRandomSequence.h:75
void SetSequencePosition(const SequenceCounterType position)
Definition: cmnRandomSequence.h:169
unsigned long ExtractRandomUnsignedLong(const unsigned long min, const unsigned long max)
Definition: cmnRandomSequence.h:322
int ExtractRandomInt(void)
Definition: cmnRandomSequence.h:235
unsigned long ExtractRandomUnsignedLong(void)
Definition: cmnRandomSequence.h:312
Provide an interface to a reproducible random sequence.
Definition: cmnRandomSequence.h:66
void ExtractRandomLongLongArray(const long long min, const long long max, long long *array, const size_t arraySize)
Definition: cmnRandomSequence.h:347
float ExtractRandomFloat(void)
Definition: cmnRandomSequence.h:201
unsigned int ExtractRandomUnsignedInt(const unsigned int min, const unsigned int max)
Definition: cmnRandomSequence.h:253
long ExtractRandomLong(const long min, const long max)
Definition: cmnRandomSequence.h:302
double ExtractRandomDouble(void)
Definition: cmnRandomSequence.h:220
char ExtractRandomChar(void)
Definition: cmnRandomSequence.h:374
void SetSeed(const SeedType seed)
Definition: cmnRandomSequence.h:152
void ExtractRandomFloatArray(const float min, const float max, float *array, const size_t arraySize)
Definition: cmnRandomSequence.h:212
void ExtractRandomPtrdiffTArray(const ptrdiff_t min, const ptrdiff_t max, ptrdiff_t *array, const size_t arraySize)
Definition: cmnRandomSequence.h:430