How to randomly generate coins in game during runtime of game?

Hi, I’m new to unity js programming and i’m trying to generate coins randomly during runtime of game.

//create array of coins, in Unity editor, size the array, drag prefab coins into the array

Public GameObject[] arrayOfCoins;

//get a random coin from the array

GameObject coin = arrayOfCoins[math.Random(0,arrayOfCoins.GetUpperbound(0))];

//instantiate the coin

Instantiate(coin , new Vector3(x, y, z), Quaternion.identity);