GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2021-07-25 09:53:28

maras
Member
Registered: 2021-04-25
Posts: 22
Website

random_range_towards

A tiny script but can be handy

also does anyone have a better name for it?

Expand/// random_range_towards(mn, mx, to, f, int)
//
// returns real
//
//	mn	min value, real
//	mx	max value, real
//	to	the result will get closer towards this value, real
//	f	force towards the desired value, real (0-1)
//	int	round the result or not, bool
//
/// GMLscripts.com/license

function random_range_towards(mn, mx, to, f, int) {

	var r = lerp(random_range(mn, mx), to, random(f));
	return int ? round(r) : r;
}

min = 0, max = 100, towards = 10

force = 0
> average: 50

force = 0.5
> average: 42

force = 1
> average: 29

Last edited by maras (2021-07-26 12:09:52)

Offline

Board footer

Powered by FluxBB