randomize awnsers (seeded)

This commit is contained in:
jusax23 2023-06-01 20:23:13 +02:00
parent c38305d38c
commit 364ea48bcd
Signed by: jusax23
GPG key ID: 499E2AA870C1CD41

View file

@ -1,3 +1,5 @@
import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:ju_learn/main.dart'; import 'package:ju_learn/main.dart';
@ -12,6 +14,7 @@ class QuizPage extends StatefulWidget {
} }
class _QuizPageState extends State<QuizPage> { class _QuizPageState extends State<QuizPage> {
int runSeed = Random().nextInt(0xffffff);
int run = 0; int run = 0;
Question _currentQuestion = Question("Dummy", ["Dummy aws"], 0, "dummy"); Question _currentQuestion = Question("Dummy", ["Dummy aws"], 0, "dummy");
int askState = -1; int askState = -1;
@ -108,7 +111,8 @@ class _QuizPageState extends State<QuizPage> {
), ),
), ),
const SizedBox(height: 20.0), const SizedBox(height: 20.0),
..._currentQuestion.answers.map( ...() {
var l = _currentQuestion.answers.map(
(option) { (option) {
return Container( return Container(
margin: const EdgeInsets.symmetric(vertical: 8.0), margin: const EdgeInsets.symmetric(vertical: 8.0),
@ -129,7 +133,10 @@ class _QuizPageState extends State<QuizPage> {
), ),
child: Text(option))); child: Text(option)));
}, },
), ).toList();
l.shuffle(Random(run + runSeed));
return l;
}(),
if (askState != -1) if (askState != -1)
Text( Text(
_currentQuestion.explanation, _currentQuestion.explanation,