KDECore
krandomsequence.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (c) 1999 Sean Harmer <sh@astro.keele.ac.uk> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License version 2 as published by the Free Software Foundation. 00007 00008 This library is distributed in the hope that it will be useful, 00009 but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 Library General Public License for more details. 00012 00013 You should have received a copy of the GNU Library General Public License 00014 along with this library; see the file COPYING.LIB. If not, write to 00015 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00016 Boston, MA 02110-1301, USA. 00017 */ 00018 #ifndef K_RANDOM_SEQUENCE_H 00019 #define K_RANDOM_SEQUENCE_H 00020 00021 #include <kdecore_export.h> 00022 #include <QtCore/QList> 00023 00040 class KDECORE_EXPORT KRandomSequence 00041 { 00042 public: 00056 explicit KRandomSequence( long lngSeed = 0 ); 00057 00061 virtual ~KRandomSequence(); 00062 00066 KRandomSequence(const KRandomSequence &a); 00067 00071 KRandomSequence &operator=(const KRandomSequence &a); 00072 00079 void setSeed( long lngSeed = 0 ); 00080 00086 double getDouble(); 00087 00094 unsigned long getLong(unsigned long max); 00095 00101 bool getBool(); 00102 00109 template<typename T> void randomize(QList<T>& list) { 00110 if (!list.isEmpty()) { 00111 QList<T> l; 00112 l.append(list.takeFirst()); 00113 while (list.count()) 00114 l.insert(int(getLong(l.count()+1)), list.takeFirst()); 00115 list = l; 00116 } 00117 } 00118 00119 00141 void modulate(int i); 00142 00143 private: 00144 class Private; 00145 Private *const d; 00146 }; 00147 00148 #endif
KDE 4.6 API Reference