serialised RNG; font update

This commit is contained in:
minjaesong
2018-09-16 03:32:12 +09:00
parent 69eb2d7a3b
commit 967eafe8a3
36 changed files with 192 additions and 71 deletions

View File

@@ -1,5 +1,6 @@
package net.torvald.random
import net.torvald.terrarum.serialise.toLittle
import net.torvald.terrarum.serialise.toLittleLong
import org.apache.commons.codec.digest.DigestUtils
import java.util.Random
@@ -12,6 +13,11 @@ class HQRNG @JvmOverloads constructor(seed: Long = System.nanoTime()) : Random()
private var s0: Long
private var s1: Long
constructor(s0: Long, s1: Long) : this() {
this.s0 = s0
this.s1 = s1
}
init {
if (seed == 0L)
throw IllegalArgumentException("Invalid seed: cannot be zero")
@@ -30,4 +36,11 @@ class HQRNG @JvmOverloads constructor(seed: Long = System.nanoTime()) : Random()
s1 = x xor y xor (x ushr 17) xor (y ushr 26)
return s1 + y
}
fun serialize() = s0.toLittle() + s1.toLittle()
fun reseed(s0: Long, s1: Long) {
this.s0 = s0
this.s1 = s1
}
}