java to C# 2 lines of code

sorry for really noob question but i have to rewrite my java script to C#, but for now i’m not too good with c# “grammar”. Need your help, here is a script:

var clipArray : AudioClip[];

function Start (){
	
	audio.PlayOneShot(clipArray[Random.Range(0, clipArray.Length)]);
	yield WaitForSeconds(3 * Random.value);
}
AudioClip[] clipArray;

public void Start ()
{
    audio.PlayOneShot(clipArray[(int)(Random.Range(0, clipArray.Length))]);
    SomeFunction();
}

public IEnumerator SomeFunction()
{
    yield return new WaitForSeconds (3 * Random.value);
}

I don’t think you’d need to cast this as an int, because if you pass Random.Range(int min, int max) the max is exclusive and it returns an int. If you pass it floats then it returns a float where the max is inclusive.

Personally, I find it to be less than intuitive.

I thought Random.Range always returns float. I need to read more carefully the documentation. And anyone who programmed with a strong typed language for some time would not find difficult to identify a cast. Maybe this is not the case since the original author said he´s still learning C#, and because of my lack of knowledge of Random I wanted a code that would work, not a intuitive one.

Well, I think that it should always return a float, but according to the docs, it doesn’t. If you want an int, you should have to cast it. We’re on the same wavelength in that regard it seems.

If proper overloading rules are followed, if you pass in two ints (such as in this example), it will return an int. If you pass in a float for either parameter, it will return a float.

Why should it always return a float?

IMO, it makes sense as is, especially for game programming, where you often need random integers. It also makes it a heck of a lot easier to grab a random element of an array.

If you need something that always returns a float, use Random.value.

I understand why it doesn’t return a float when given two integers, I just think it would be easier for people to keep straight.

I think that this statement: SomeFunction();
should be: StartCoroutine(SomeFunction());

Yep, you´re right, thanks for the correction.

Thank U guys!

It’s not java, it’s javascript…