-
-
Save MBDesu/43eb908f24281f9ffe2d297b158cd68f to your computer and use it in GitHub Desktop.
a Golang implementation of Vsav's PRNG function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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