#Pseudorandom UUID with Seed

6 messages · Page 1 of 1 (latest)

knotty eagle
#
function pseudoRandomUUID(seedString){
    const $CompoundTag = Java.loadClass("net.minecraft.nbt.CompoundTag")
    const tag = new $CompoundTag()
    tag.putString("4fb32ac0-c684-4828-9992-4e122191c65d", seedString)
    const seed = tag.hashCode()
    const random = Utils.newRandom(seed)
    const byteArray = Array(32).fill(0).map(_ => Array(4).fill(0).map(_ => random.nextBoolean()).reduce((a, b, index) => (a + b * (2 ** index))))
    const $UUID = Java.loadClass("java.util.UUID")
    return $UUID.nameUUIDFromBytes(byteArray)
}

This uses a string to produce pseudo-random UUID. It's probably only useful in very specific scenario, but I decide to share this anyway.

junior juniper
#

...huh?

junior juniper
knotty eagle
#

because that's not seeded

junior juniper
#

Oh I see

junior juniper