Skip to content

Instantly share code, notes, and snippets.

@mjtb49
mjtb49 / lcg_log.py
Last active February 21, 2024 14:35
Earthcomputer requested that I write up a lcg discrete log solver for arbitrary lcgs. I have now done so, but lazily, there are several points where this could be improved and I am not entirely convinced by the approach. This solver assumes some sort of factorization is possible - in particular it needs to factor both phi(m) and m at some point …
import math
import sympy
import sympy as sp
import random
class LCG:
def __init__(self, a, b, m):
self.a = a % m
@mjtb49
mjtb49 / LootTableRNG.java
Last active September 21, 2023 11:20
1.20-pre4 Loot Example
import com.google.common.base.Charsets;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.primitives.Longs;
import java.util.Random;
public class LootTableRNG {
private static final HashFunction MD5 = Hashing.md5();
import java.util.*;
public class AdditionUnderXOR {
static final int SS = 1000000;
enum Ore {
COAL(60005),
IRON(60006),
@mjtb49
mjtb49 / main.py
Created June 7, 2022 04:08
Factoring Polynomials Mod 2
import random
class GF2Poly:
def __init__(self, c):
self.c = c
def __add__(self, other):
return GF2Poly(other.c ^ self.c)
import java.util.Random;
import java.util.UUID;
public class UUIDBonker {
public static UUID randomUuid(Random random) {
//fabric mappings seem to call m and l the other way round. This disagrees with UUID constructor.
long m = random.nextLong() & -61441L | 16384L;
long l = random.nextLong() & 4611686018427387903L | Long.MIN_VALUE;
return new UUID(m,l);
import kaptainwutax.biomeutils.source.NetherBiomeSource;
import kaptainwutax.featureutils.structure.NetherFossil;
import kaptainwutax.seedutils.mc.MCVersion;
import java.util.Random;
public class NetherFossils {
static final NetherFossil FOSSIL = new NetherFossil(MCVersion.v1_16_1);
public static void printSomeFossilSeeds(int some) {
Random r = new Random();
/**
* An example to show basic functionality of KaptainWutax's libraries
* and common usage patterns.
*/
import kaptainwutax.biomeutils.source.OverworldBiomeSource;
import kaptainwutax.featureutils.structure.Village;
import kaptainwutax.seedutils.mc.ChunkRand;
import kaptainwutax.seedutils.mc.MCVersion;
import kaptainwutax.seedutils.mc.pos.CPos;
@mjtb49
mjtb49 / NextLongEquivalentFinder.java
Created September 27, 2020 20:21
A class providing a fast algorithm for converting a 48 bit structure seed to a nextLong with the same lower 48 bits.
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class NextLongEquivalentFinder {
//{0, 107048004364969} offsets
//{{-33441*2/(32768*2), 46603/65536}, {17549*2/(32768*2), 39761/65536}}/65536 will be our inverse matrix
@mjtb49
mjtb49 / MushroomCondition.java
Created September 5, 2020 20:35
A small class to demonstrate an idea for biome seedfinding
/**
* An example of the method for the specific case of finding patterns of mushroom islands. Some things,
* like the layerseed will be hardcoded which should eventually be computed dynamically
* depending on which layer and nextInt call the user wishes to target.
*/
public class MushroomCondition {
final static long SHROOM_LAYER_SEED = -7479281634960481323L; //must be computed for each layer, maybe a LUT?
final static long EPSILON = (1L << 32);
@mjtb49
mjtb49 / gist:a9b750e0048c09ada31896e5617f4fd0
Created April 19, 2020 20:42
A reversal of the pikmin LCG from some inequalities
import copy
def lcg(seed):
return (seed*1103515245+12345) % 2**31
def invlcg(seed):
return ((seed-12345)*1857678181) % 2**31
def getCeils(list):
newlist = []