Math.random in JS

I’m trying to generate a random number in javascript and I’ve hit a very frustrating issue. According to every script I’ve ever done, as well as 5 different websites to verify my sanity, random is done in javascript using Math.random(). I have a min and max that I want for the random to fall under, so I put this function together:

function randint( beg, end )
{
    return Math.floor(((end - beg + 1)*Math.random()));
}

Unity returns an error:
unknown identifier ‘Math’.

I put together a script without the min/max to simplify things:

 function randint()
{
	var rand_no = Math.random();
	return rand_no;
}

unknown identifier: ‘Math’.

Is it my fault trying to code in the brain fog shortly after waking up, or is something seriously wrong here?

JS in Unity isn’t actually JavaScript, it’s an ECMAScript implementation Unity calls JavaScript for promotional purposes. It’s better thought of as UnityScript.

Unity provides a Random class; you should use Random.Range().

Ah, thanks for the response and the distinction. I’ll give that a shot when I get home tonight.

Random.value is a random number from zero to one, while Random.range is a random number from the min value to the max value. (num = Random.range(1.5, 4.5) or num = Random.value)

other Math functions are available via Mathf