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 / mulberry32.c
Last active February 5, 2024 20:32
Mulberry32 PRNG
/* Written in 2017 by Tommy Ettinger (tommy.ettinger@gmail.com)
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/>. */
#include <stdint.h>
@tommyettinger
tommyettinger / thrust.c
Last active October 14, 2023 14:53
Thrust Pseudo-Random Number Generator
/* Written in 2017 by Tommy Ettinger (tommy.ettinger@gmail.com)
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/>. */
#include <stdint.h>
@tommyettinger
tommyettinger / StartOnFirstThreadHelper.java
Created April 26, 2023 04:17
-XstartOnFirstThread (Magic)
/*
* Copyright 2020 damios
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@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
@tommyettinger
tommyettinger / Random-Game-Ideas.txt
Last active October 23, 2022 13:03
Randomly generated indie game ideas
This random game idea generator was a collaboration between David O'Toole (dto)
and myself (Tommy Ettinger). The generator is a Clojure program that is available
to fork and tweak at http://ideone.com/0MG8ED .
@tommyettinger
tommyettinger / IndexedDictionary.cs
Created March 1, 2020 03:38
C# insertion-ordered Dictionary that allows lookup by index.
using System;
using System.Collections;
using System.Collections.Generic;
namespace SquidLib.SquidMath {
/// <summary>
/// Only for use with indexers in IndexedDictionary to show you want to access a key.
/// There is only one enum constant here, At.
/// </summary>
public enum Key {
@tommyettinger
tommyettinger / MemoryUsageOfDataStructures.txt
Created June 15, 2019 23:16
Memory usage of data structures on the JVM
This includes JDK8 and Guava 28 data structures, with the analysis done by https://github.com/DimitrisAndreou/memory-measurer .
========================================== 64-bit architecture ==========================================
========================================== Basic Lists, Sets, Maps ==========================================
ArrayList :: Bytes = 4.71, Objects = 0.00 Refs = 1.18 Primitives = {}
ImmutableList :: Bytes = 4.00, Objects = 0.00 Refs = 1.00 Primitives = {}
HashSet :: Bytes = 40.24, Objects = 1.00 Refs = 5.06 Primitives = {int=1.0}
@tommyettinger
tommyettinger / DeepMap.txt
Created January 1, 2021 22:28
Multi-layer dungeon map; '<' and '>' are staircases
--------------------------------------------------- depth 0
┌───┐┌────┐ ┌─┐ ┌────┐
┌┘.""└┘....└┐ ┌┘.└┐ ┌┘....└┐
┌┘...""...#..│┌────────┐ ┌┘...└┐│..#...└──┐
│............└┘.,~~~~,.└──┐ │.....││.........└┐
└┐..............───~~.....└┐ └┐...─┴┘...│..┌┐..│ ┌─┐
│...............,,~~......│ │.........│..└┘..└─┬────┘.└┐
├─.────.........,.┌┐......│ └┐.┌──┐...└─.......│.......└┐
│................┌┘│.....┌┘ └─┘ │.....................│
└┐.┌──┐.┌┐....┌──┴┐├─..┌─┴┐ │...┌──┐.............┌┘
@tommyettinger
tommyettinger / CLEANED_UP.txt
Last active September 7, 2020 08:21
SquidLib DungeonGenerator sample given TilesetType.DEFAULT_DUNGEON
┌─────────────┬─────┬───────────────┐ ┌─────┬───────────┐ ┌─────┐ ┌───────┐ ┌─────────┐ ┌─────┬───────────┐ ┌─────────┐
│ . . . . . . │ . . │ . . . . . . . └───┘ . . │ . . . . . │ │ . . │ ┌─┘ . . . ├───────────────┘ . . . . └───┘ . . │ . . . . . │ │ . . . . │
│ . . . . . . │ . . │ . . ────. . . . . . . . │ . . . . . ├───────┘ . . └─┐ │ . . . . │ . . . . . . . . . . . . . . . . . │ . . . . . │ ┌─┘ . . . ┌─┘
│ . . │ . ┌───┘ . . │ . . . . . . . . . . . . │ . . . . . │ . . . . . . . │ │ . . . ┌─┤ . . . . . . . . . . . . . . . . . │ . . . . . └─┘ . . . . └───┐
│ . . │ . │ . . . . . . . ──┬───────┬───┐ . . └─+ ──┐ . . . . . . . . . . │ │ . . ┌─┘ │ . . │ . . ┌───+ ┬─┐ . . ┌───┐ . . │ . . │ . . . . . . . . . . └─┐
│ . . │ . │ . . . . . . . . │ . . . │ │ . . . . . │ . . . . . . ┌─┐ . . └─────┘ . . └───┘ . . │ . . │ . . │ │ . . │ │ . . . . . │ . . . . . . . . . . . └─┐
│ . . . . │ . . . . │ . . . │ . . . │ │ . . . . . │ . .
@tommyettinger
tommyettinger / Probit.java
Created August 13, 2020 23:49
Probit function in Java
/**
* Provides a {@link #probit(double)} method to convert from the (0.0,1.0) domain to a Gaussian range.
* Uses an algorithm by Peter John Acklam, as implemented by Sherali Karimov.
* Free to use, but you should credit Acklam and Karimov appropriately.
*/
public final class Probit {
private static final double LOW = 0.02425;
private static final double HIGH = 1.0 - LOW;
// Coefficients in rational approximations.