Skip to content

Instantly share code, notes, and snippets.

function Random(seed) {
this.seed = Math.random() * Math.pow(2,31);
this.a = 1103515245;
this.c = 12345;
this.m = Math.pow(2, 31);
}
Random.prototype.next = function() {
this.seed = (this.a * this.seed + this.c) % this.m;
return this.seed;
@jonikarppinen
jonikarppinen / CustomErrorController.java
Last active June 16, 2021 02:19
Example of replacing Spring Boot "whitelabel" error page with custom error responses (with JSON response body)
package com.company.project.controllers;
import com.company.project.model.api.ErrorJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.web.ErrorAttributes;
import org.springframework.boot.autoconfigure.web.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;