Skip to content

Instantly share code, notes, and snippets.

@MBDesu
Created July 28, 2025 17:28
Show Gist options
  • Select an option

  • Save MBDesu/43eb908f24281f9ffe2d297b158cd68f to your computer and use it in GitHub Desktop.

Select an option

Save MBDesu/43eb908f24281f9ffe2d297b158cd68f to your computer and use it in GitHub Desktop.
a Golang implementation of Vsav's PRNG function
package main
import "fmt"
var currSeed = 0x01 // 0xff80d4
var currPrn = 0xc3 // 0xff80d5
func main() {
for range 12 {
getNextRng()
}
}
func getNextRng() int {
var newSeedAndPrn = getSeedAndPrnAsWord()
newSeedAndPrn *= 3
newSeedAndPrn &= 0xffff // keep it 16 bit
newSeedAndPrn /= 256 // lsr 8
var newSeed = newSeedAndPrn & 0xff // lower byte only
currPrn += newSeed
currPrn &= 0xff
currSeed = newSeed
currSeed &= 0xff
fmt.Printf("0xff80d4.w = 0x%.04x\n", getSeedAndPrnAsWord())
return currPrn
}
func getSeedAndPrnAsWord() int {
return (currSeed << 8) | currPrn
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment