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.random;
|
||||||
import std.file;
|
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;
|
Mt19937 gen;
|
||||||
gen.seed(unpredictableSeed);
|
gen.seed(unpredictableSeed);
|
||||||
args.randomShuffle(gen);
|
args.randomShuffle(gen);
|
||||||
} else if (t == "x"){
|
break;
|
||||||
|
case "x":
|
||||||
Xorshift32 gen;
|
Xorshift32 gen;
|
||||||
gen.seed(unpredictableSeed);
|
gen.seed(unpredictableSeed);
|
||||||
args.randomShuffle(gen);
|
args.randomShuffle(gen);
|
||||||
} else if (t == "du"){
|
break;
|
||||||
|
case "du":
|
||||||
auto gen = DevRandomGen!"/dev/urandom"();
|
auto gen = DevRandomGen!"/dev/urandom"();
|
||||||
args.randomShuffle(gen);
|
args.randomShuffle(gen);
|
||||||
} else if (t == "dr"){
|
break;
|
||||||
|
case "dr":
|
||||||
auto gen = DevRandomGen!"/dev/random"();
|
auto gen = DevRandomGen!"/dev/random"();
|
||||||
args.randomShuffle(gen);
|
args.randomShuffle(gen);
|
||||||
} else {
|
break;
|
||||||
throw new Exception("Wrong arguments");
|
default:
|
||||||
|
r = Error();
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
return args;
|
|
||||||
|
r = args;
|
||||||
|
return r ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue