Nice Code Snippets
Elscherino / April 2026 (84 Words, 1 Minutes)
Table of Contents
A showcase of syntax highlighting across languages.
Random list pick without duplicates
private int currentIndex;
private List<object> objectList = new();
public object RandomPickDifferentFromLast()
{
objectCount = objectList.Count;
currentIndex = (currentIndex + Random.Range(1, objectCount - 1)) % objectCount;
return objectList[currentIndex];
}
Lerping
public float Lerp(float a, float b, float t) {
return (1f - t) * a + b * t;
}
public float InvLerp(float a, float b, float v) {
return (v - a) / (b - a);
}
// combine the two
public float Remap(float iMin, float iMax, float oMin, float oMax, float v) {
float t = InvLerp(iMin, iMax, v);
return Lerp(oMin, oMax, t)
}
© 2020 - 2026 Elscherino
•
Theme Moonwalk