1 /* Invisible Vector Library
2 * coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
3 * Understanding is not required. Only obedience.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License ONLY.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module iv
.prng
.seeder
/*is aliced*/;
21 public uint xyzzyPRNGHashU32() (uint a
) {
33 public uint getTwoUintSeeds (uint* second
=null) nothrow @trusted @nogc {
35 import core
.sys
.windows
.windef
, core
.sys
.windows
.winbase
;
36 uint s0
= xyzzyPRNGHashU32(cast(uint)GetCurrentProcessId());
37 uint s1
= xyzzyPRNGHashU32(cast(uint)GetTickCount());
38 if (second
is null) return s0^s1
;
43 import core
.sys
.posix
.fcntl
;
44 import core
.sys
.posix
.unistd
;
45 uint s0
= 0xdeadf00du
;
46 int fd
= open("/dev/urandom", O_RDONLY
);
48 // assume that we always have endless supply of bytes from that
49 read(fd
, &s0
, s0
.sizeof
);
50 if (second
!is null) read(fd
, second
, (*second
).sizeof
);
54 // try something another
55 import core
.sys
.posix
.unistd
;
56 import core
.sys
.posix
.time
;
57 s0
= cast(uint)xyzzyPRNGHashU32(cast(uint)getpid());
59 if (clock_gettime(CLOCK_MONOTONIC
, &stt
) == 0) {
60 uint s1
= xyzzyPRNGHashU32(cast(uint)(stt
.tv_sec^stt
.tv_nsec
));
61 if (second
is null) return s0^s1
;
65 if (second
is null) *second
= xyzzyPRNGHashU32(s0
);
71 public ulong getUlongSeed () nothrow @trusted @nogc {
73 uint s0
= getTwoUintSeeds(&s1
);
74 return ((cast(ulong)s1
)<<32)|s0
;