Skip to content

Instantly share code, notes, and snippets.

@thinca
Created April 8, 2014 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinca/10114309 to your computer and use it in GitHub Desktop.
Save thinca/10114309 to your computer and use it in GitHub Desktop.
function! GenerateCanonical()
let b = 32
let r = (0x7fffffff + 0.0) - (0x80000000 + 0.0) + 1.0
let log2r = float2nr(log(r) / log(2.0))
let k = max([1, (b + log2r - 1) / log2r])
let sum = 0.0
let tmp = 1.0
while k != 0
let sum += (g:V.Random.rand() - (0x80000000 + 0.0)) * tmp
let tmp = tmp * r
let k -= 1
endwhile
return sum / tmp
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment