KCoreAddons

krandomsequence.h
1 /*
2  This file is part of the KDE libraries
3 
4  SPDX-FileCopyrightText: 1999 Sean Harmer <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-only
7 */
8 
9 #ifndef K_RANDOM_SEQUENCE_H
10 #define K_RANDOM_SEQUENCE_H
11 
12 #include <kcoreaddons_export.h>
13 #include <QList>
14 
31 class KCOREADDONS_EXPORT KRandomSequence
32 {
33 public:
50  explicit KRandomSequence(int intSeed = 0);
51  explicit KRandomSequence(long lngSeed);
52 
56  virtual ~KRandomSequence();
57 
62 
66  KRandomSequence &operator=(const KRandomSequence &a);
67 
74  void setSeed(int intSeed = 0);
75  void setSeed(long lngSeed = 0);
76 
82  double getDouble();
83 
90  unsigned int getInt(unsigned int max);
91  unsigned long getLong(unsigned long max);
92 
98  bool getBool();
99 
112  template<typename T> void randomize(QList<T> &list)
113  {
114  // Fisher-Yates algorithm
115  for (int index = list.count() - 1; index > 0; --index) {
116  const int swapIndex = getInt(index + 1);
117  qSwap(list[index], list[swapIndex]);
118  }
119  }
120 
142  void modulate(int i);
143 
144 private:
145  class Private;
146  Private *const d;
147 };
148 
149 #endif
void randomize(QList< T > &list)
Put a list in random order.
int count(const T &value) const const
A class to create a pseudo-random sequence.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Wed May 27 2020 23:06:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.