Changeset View
Changeset View
Standalone View
Standalone View
lib/slideshow.cpp
Show First 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | |||||
64 | public: | 64 | public: | ||
65 | RandomNumberGenerator() | 65 | RandomNumberGenerator() | ||
66 | : mSeed(time(0)) | 66 | : mSeed(time(0)) | ||
67 | { | 67 | { | ||
68 | } | 68 | } | ||
69 | 69 | | |||
70 | int operator()(int n) | 70 | int operator()(int n) | ||
71 | { | 71 | { | ||
72 | #ifdef WIN32 | ||||
73 | return rand() % n; | ||||
kfunk: Probably the more modern (and cross-platform way to do this) is to use this instead of the… | |||||
Note that rand() without srand() before will generate the same series of random numbers each program run (cf. https://www.geeksforgeeks.org/rand-and-srand-in-ccpp/) -- not what the Unix version here does! kfunk: Note that `rand()` without `srand()` before will generate the same series of random numbers… | |||||
74 | #else | ||||
72 | return rand_r(&mSeed) % n; | 75 | return rand_r(&mSeed) % n; | ||
76 | #endif | ||||
73 | } | 77 | } | ||
74 | 78 | | |||
75 | private: | 79 | private: | ||
76 | unsigned int mSeed; | 80 | unsigned int mSeed; | ||
77 | }; | 81 | }; | ||
78 | 82 | | |||
79 | struct SlideShowPrivate | 83 | struct SlideShowPrivate | ||
80 | { | 84 | { | ||
▲ Show 20 Lines • Show All 247 Lines • Show Last 20 Lines |
Probably the more modern (and cross-platform way to do this) is to use this instead of the RandomNumberGenerator and std::random_shuffle in initShuffledUrls() file:
See: https://stackoverflow.com/questions/6926433/how-to-shuffle-a-stdvector
(seed() is needed so the random numbers generated by generator are not the same on consecutive runs of the program)