mirror of
https://github.com/FraMecca/Buridans_donkey.git
synced 2024-03-20 11:20:15 +01:00
use of union types in shuffle.
Also switch instead of if else
This commit is contained in:
parent
209707f0b9
commit
4799d9d58b
1 changed files with 28 additions and 8 deletions
|
@ -3,26 +3,46 @@ import std.array : array;
|
|||
import std.random;
|
||||
import std.file;
|
||||
|
||||
const (string[]) shuffle(string[] args, const string t)
|
||||
import vibe.http.server;
|
||||
import taggedalgebraic;
|
||||
|
||||
struct Error {};
|
||||
union U {
|
||||
string[] args;
|
||||
Error e;
|
||||
}
|
||||
|
||||
alias Result = TaggedUnion!U;
|
||||
|
||||
auto shuffle(string[] args, const string t)
|
||||
{
|
||||
if(t == "mt"){
|
||||
Result r;
|
||||
switch(t){
|
||||
case "mt":
|
||||
Mt19937 gen;
|
||||
gen.seed(unpredictableSeed);
|
||||
args.randomShuffle(gen);
|
||||
} else if (t == "x"){
|
||||
break;
|
||||
case "x":
|
||||
Xorshift32 gen;
|
||||
gen.seed(unpredictableSeed);
|
||||
args.randomShuffle(gen);
|
||||
} else if (t == "du"){
|
||||
break;
|
||||
case "du":
|
||||
auto gen = DevRandomGen!"/dev/urandom"();
|
||||
args.randomShuffle(gen);
|
||||
} else if (t == "dr"){
|
||||
break;
|
||||
case "dr":
|
||||
auto gen = DevRandomGen!"/dev/random"();
|
||||
args.randomShuffle(gen);
|
||||
} else {
|
||||
throw new Exception("Wrong arguments");
|
||||
break;
|
||||
default:
|
||||
r = Error();
|
||||
return r;
|
||||
}
|
||||
return args;
|
||||
|
||||
r = args;
|
||||
return r ;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue