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
type Whatever struct { | |
someField int | |
} | |
func (w Whatever) MarshalJSON() ([]byte, error) { | |
return json.Marshal(struct{ | |
SomeField int `json:"some_field"` | |
}{ | |
SomeField: w.someField, | |
}) |
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
// Mersenne Twister 19937 | |
// Based on code from: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html | |
// Note: This implementation is not thread-safe! | |
final class MersenneTwister (seed: Int = 5489) { | |
private val N = 624 | |
private val M = 397 | |
private val MatrixA = 0x9908b0dfL | |
private val UpperMask = 0x80000000L |
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
/* | |
I've wrapped Makoto Matsumoto and Takuji Nishimura's code in a namespace | |
so it's better encapsulated. Now you can have multiple random number generators | |
and they won't stomp all over eachother's state. | |
If you want to use this as a substitute for Math.random(), use the random() | |
method like so: | |
var m = new MersenneTwister(); |