cdc/tools/gen.d

48 lines
899 B
D
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/rdmd
module tools.gen;
import std.stdio;
import std.random : Random, unpredictableSeed, uniform;
void main()
{
enum N = 256;
ulong[N] gear;
auto rng = Random(unpredictableSeed);
bool[ulong] seen;
ulong[] vals;
vals.reserve(N);
while (vals.length < N)
{
const v = uniform!ulong(rng);
if (v in seen)
continue;
seen[v] = true;
vals ~= v;
}
gear[] = vals[0 .. N];
writeln("immutable ulong[256] gear = [");
foreach (i, v; gear)
{
// Индент только в начале каждой строки
if (i % 4 == 0)
write("\t");
writef("0x%016x", v);
if (i != N - 1) // не ставим запятую после последнего
write(",");
// Перенос после каждого 4-го элемента или в самом конце
if ((i + 1) % 4 == 0 || i == N - 1)
writeln();
else
write(" ");
}
writeln("];");
}