Skip to content

Instantly share code, notes, and snippets.

View laher's full-sized avatar

Amir Laher laher

  • TixTrack
  • Auckland
View GitHub Profile
@kendellfab
kendellfab / golang-json-marshall
Created August 16, 2013 22:35
Handling custom Json marshalling in golang.
type Whatever struct {
someField int
}
func (w Whatever) MarshalJSON() ([]byte, error) {
return json.Marshal(struct{
SomeField int `json:"some_field"`
}{
SomeField: w.someField,
})
@jesperdj
jesperdj / MersenneTwister.scala
Created March 25, 2011 22:28
Mersenne Twister - Random number generator
// 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
@banksean
banksean / mersenne-twister.js
Created February 10, 2010 16:24
a Mersenne Twister implementation in javascript. Makes up for Math.random() not letting you specify a seed value.
/*
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();