@@ -43,11 +43,13 @@ Dice::Dice(Controllers::MotionController& motionController,
4343 Controllers::MotorController& motorController,
4444 Controllers::Settings& settingsController)
4545 : motorController {motorController}, motionController {motionController}, settingsController {settingsController} {
46- std::seed_seq sseq {static_cast <uint32_t >(xTaskGetTickCount ()),
47- static_cast <uint32_t >(motionController.X ()),
48- static_cast <uint32_t >(motionController.Y ()),
49- static_cast <uint32_t >(motionController.Z ())};
50- gen.seed (sseq);
46+ rng.state =
47+ (static_cast <uint64_t >(xTaskGetTickCount ()) << 32 ) ^ (static_cast <uint64_t >(motionController.NbSteps ()) << 16 ) ^ (uint64_t ) &rng;
48+ rng.inc = (static_cast <uint64_t >(motionController.X ()) << 32 ) ^ (static_cast <uint64_t >(motionController.Y ()) << 16 ) ^
49+ static_cast <uint64_t >(motionController.Z ());
50+ uint8_t discard = pcg32_random_r (&rng);
51+ for (uint32_t i = 0 ; i < discard; i++)
52+ pcg32_random_r (&rng);
5153
5254 lv_obj_t * nCounterLabel = MakeLabel (&jetbrains_mono_bold_20,
5355 LV_COLOR_WHITE,
@@ -79,8 +81,7 @@ Dice::Dice(Controllers::MotionController& motionController,
7981 lv_obj_align (dCounter.GetObject (), dCounterLabel, LV_ALIGN_OUT_BOTTOM_MID, 0 , 10 );
8082 dCounter.SetValue (6 );
8183
82- std::uniform_int_distribution<> distrib (0 , resultColors.size () - 1 );
83- currentColorIndex = distrib (gen);
84+ currentColorIndex = bounded_rand (rng, resultColors.size ());
8485
8586 resultTotalLabel = MakeLabel (&jetbrains_mono_42,
8687 resultColors[currentColorIndex],
@@ -157,12 +158,10 @@ void Dice::Refresh() {
157158void Dice::Roll () {
158159 uint8_t resultIndividual;
159160 uint16_t resultTotal = 0 ;
160- std::uniform_int_distribution<> distrib (1 , dCounter.GetValue ());
161-
162161 lv_label_set_text (resultIndividualLabel, " " );
163162
164163 if (nCounter.GetValue () == 1 ) {
165- resultTotal = distrib (gen) ;
164+ resultTotal = bounded_rand (rng, dCounter. GetValue ()) + 1 ;
166165 if (dCounter.GetValue () == 2 ) {
167166 switch (resultTotal) {
168167 case 1 :
@@ -175,7 +174,7 @@ void Dice::Roll() {
175174 }
176175 } else {
177176 for (uint8_t i = 0 ; i < nCounter.GetValue (); i++) {
178- resultIndividual = distrib (gen) ;
177+ resultIndividual = bounded_rand (rng, dCounter. GetValue ()) + 1 ;
179178 resultTotal += resultIndividual;
180179 lv_label_ins_text (resultIndividualLabel, LV_LABEL_POS_LAST, std::to_string (resultIndividual).c_str ());
181180 if (i < (nCounter.GetValue () - 1 )) {
0 commit comments