Skip to content

Instantly share code, notes, and snippets.

View blixt's full-sized avatar
🚀
???

Blixt blixt

🚀
???
View GitHub Profile
var pocket = require('pocket');
// Traits just need to implement an interface and can be instances or singletons (see anonymous trait below for
// interface).
var controller = require('./traits/controller');
var health = require('./traits/health');
var score = require('./traits/score');
var verlet = require('./traits/verlet');
var player = pocket.entity({name: 'Blixt'});
@blixt
blixt / index.js
Last active December 29, 2020 14:32
requirebin sketch
var procedural = require('procedural');
var avatar = procedural('avatar')
// The block size is just visual, so it shouldn't affect randomization.
.doNotHash('blockSize')
// The username is needed to create a unique avatar for every user.
.takes('username')
// Size, in blocks. Different sizes will create different avatars.
.takes('size', function validate(avatar, blocks) {
// Ensure that size is a positive integer divisible by 2.
@blixt
blixt / Alea(2)
Created August 3, 2014 07:31
Dieharder run on procedural Alea with two seeds (500,000,000 values)
./randout.js --prng Procedural --count 500000000 > proc-alea2.txt && dieharder -g 202 -f proc-alea2.txt -a
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| proc-alea2.txt| 3.77e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
diehard_birthdays| 0| 100| 100|0.09460678| PASSED
@blixt
blixt / testasm.html
Created August 2, 2014 21:00
Slow asm.js procedure
<!DOCTYPE html>
<html>
<head><meta charset="utf-8"><title>asm.js</title></head>
<body>
<script>
function murmurhash3(stdlib, foreign, heap) {
"use asm";
var int32 = new stdlib.Int32Array(heap);
@blixt
blixt / Alea
Created August 2, 2014 18:05
Results of running Dieharder on procedural PRNGs
#=============================================================================#
# dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
#=============================================================================#
rng_name | filename |rands/second|
file_input| alea.txt| 3.72e+06 |
#=============================================================================#
test_name |ntup| tsamples |psamples| p-value |Assessment
#=============================================================================#
# The file file_input was rewound 1 times
diehard_birthdays| 0| 100| 100|0.91201959| PASSED
@blixt
blixt / asm.js
Created August 2, 2014 15:50
Slow asm.js?
function murmurhash3(stdlib, foreign, heap) {
"use asm";
var int32 = new stdlib.Int32Array(heap);
function murmurhash3_32(idx, len, seed) {
idx = idx | 0;
len = len | 0;
seed = seed | 0;
var h = 0, k = 0, i = 0;
@blixt
blixt / TestingRNGs.md
Last active November 5, 2021 13:42
Testing random number generators with DieHarder

Testing RNGs with Dieharder

This guide is specifically for pseudo-random number generators (PRNGs) written in JavaScript, and tested in Mac OS X.

Prerequisites

Homebrew

@blixt
blixt / procedural-avatar.js
Last active December 29, 2020 14:32
Procedural avatars using procedural.
var avatar = procedural('avatar')
.takes('username')
// Size, in blocks.
.takes('size', function validate(avatar, blocks) {
return typeof blocks == 'number' && blocks > 0;
})
// The pixel size of a single (square) block.
.takes('blockSize', function validate(avatar, px) {
return typeof px == 'number' && px > 0;
})
@blixt
blixt / prng.js
Last active January 3, 2026 05:52
A very simple, seedable JavaScript PRNG. NOTE: Please read comments on why this is not a good choice.
// NOTICE 2020-04-18
// Please see the comments below about why this is not a great PRNG.
// Read summary by @bryc here:
// https://github.com/bryc/code/blob/master/jshash/PRNGs.md
// Have a look at js-arbit which uses Alea:
// https://github.com/blixt/js-arbit
/**
@blixt
blixt / index.js
Created July 24, 2014 21:01
requirebin sketch
var fnv = require('fnv-plus');
for (var i = 0; i < 100; i++)
console.log(fnv.hash(i.toString(), 32).value);