Skip to content

Instantly share code, notes, and snippets.

View tommyettinger's full-sized avatar
⚙️
Keeping the commit streak alive

Tommy Ettinger tommyettinger

⚙️
Keeping the commit streak alive
View GitHub Profile
@tommyettinger
tommyettinger / $_$.java
Created October 11, 2017 03:54
Dollar Eyes Dot Java
/*
MIT License
Copyright (c) 2017 Tommy Ettinger
Based on lz-string4java, which is:
Copyright (c) 2016 rufushuang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@tommyettinger
tommyettinger / RandomUtils.java
Created July 9, 2017 05:59
Tiny Java utilities for generating high-quality random int values from a large state array
public class RandomUtils
{
/**
* Generates a state array for use with {@link #randomInt(int[])}; this state array will be random using {@code Math.random()}.
* @return a 129-element int array with contents randomized by {@code Math.random()}
*/
public static int[] initialState()
{
final int[] state = new int[129];
for(int i = 0; i < 129; i++)
@tommyettinger
tommyettinger / CurvedRandom.java
Created July 4, 2017 00:21
Simple, fast curved-distribution random number generator. For LibGDX applications.
package change.this;
import com.badlogic.gdx.utils.NumberUtils;
public class CurvedRandom
{
private long state0, state1;
/**
* Gets a roughly 96-bit random seed using Math.random().
*/
@tommyettinger
tommyettinger / PRNG.cs
Last active September 29, 2017 04:28
Pseudo-random number generator in C#; compatible with System.Random
using System;
/*
A faster drop-in replacement for System.Random with added features for copying and storing state.
But why replace System.Random in the first place, you ask?
A few reasons. One is discussed here, with the apparent consensus that it won't change:
https://connect.microsoft.com/VisualStudio/feedback/details/634761/system-random-serious-bug
(The formatting on that page is pretty lousy, so the text is here as well for convenience.)
"""While investigating the period of various random number generators, I found a serious bug in
Microsoft .NET System.Random implementation.
Microsoft Documentation (http://msdn.microsoft.com/en-us/library/system.random.aspx) says that
#[ Written by Tommy Ettinger in 2017, based on work by Melissa O'Neill in 2015:
PCG-Random, http://www.pcg-random.org/
To the extent possible under law, the author has dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
See <http://creativecommons.org/publicdomain/zero/1.0/>. ]#
var x*: uint64 # The state can be seeded with any value.
package com.carterza.planet.map.generator.pathfind;
import com.badlogic.gdx.ai.pfa.Connection;
import com.badlogic.gdx.ai.pfa.Heuristic;
/**
* Created by zachcarter on 12/20/16.
*/
public class TiledElevationDistance<N extends TiledTerrainNode> implements Heuristic<N> {
private Coord findLowerElevation(Coord currentLocation, GreasedRegion riverBlockages,
GreasedRegion heights, GreasedRegion reuse, GreasedRegion temp) {
heights.refill(heightData.data, Sand, heightData.data[currentLocation.x][currentLocation.y])
.andNot(riverBlockages);
reuse.clear().insert(currentLocation);
temp.remake(reuse).fringe();
int searchDistance = 40;
for(int d = 1; d < searchDistance; d++)
{
@tommyettinger
tommyettinger / FactionMap.java
Last active December 17, 2016 23:41 — forked from zacharycarter/FactionMap.java
Update hoping to fix
private void generateFactionMap(final int factionCount, double controlledFraction) {
MultiSpill spreader = new MultiSpill(new short[WIDTH][HEIGHT], Spill.Measurement.MANHATTAN, CommonRNG.getRng());
OrderedMap<Coord, Double> entries = new OrderedMap<>();
char[][] map = new char[WIDTH][HEIGHT];
short[][] regionMap = new short[WIDTH][HEIGHT];
for(int x = 0; x < WIDTH; x++) {
for(int y = 0; y < HEIGHT; y++) {
if(tiles[x][y].heightValue >= Sand)
@tommyettinger
tommyettinger / WorldMaps.txt
Created December 11, 2016 09:05
More SpillWorldMap results from SquidLib, now with varying water amounts and wilderness-to-controlled-land ratios
Mu_120x75
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~jj~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~jjjTTTTT~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~jjjjjjTTTTTT~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~jjjjjTTTTTTT~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%~~~~~~~~~~~~~~~~~~~~~~~~~~~~f~~%H~~~~~~~~~~~~~~jjjjjTTTTTTT~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~%~~~~N%%~~~~
@tommyettinger
tommyettinger / Halton.java
Created November 25, 2016 23:05
Quick and easy Halton sequence point generator for libGDX
/**
* Gets a quasi-random Vector2 between (0f,0f) inclusive and (1f,1f) exclusive, assigning into {@code into} the
* {@code index}-th point in the (2, 3) Halton sequence. If index is unique, the Vector2 should be as well for all
* but the largest values of index. You might find an advantage in using values for index that start higher than
* 20 or so, but you can pass sequential values for index and generally get Vector2s that won't be near each other;
* this is not true for all parameters to Halton sequences, but it is true for this one.
* @param into the Vector2 to place the result into and return
* @param index an int that, if unique, positive, and not too large, will usually result in unique Vector2 values
* @return into, modified; usually will have a comfortable distance from Vector2s produced with close index values