UnityEngine.Random.Range is simpler to understand than System.Random.Next, and probably the one you want to be using in this case. It is also included in the UnityEngine namespace so you do not need to import anything extra.
As you want to be generating integers, you would pass in integers to the method, but you must remember that the minimum value is inclusive (i.e. it has a chance to be picked), however the maximum value is exclusive (i.e. it will not be picked, but the integer below it will). It is this way because the Unity team know that people are going to be using it to generate random index values often, and as you already know indexing in C# (and most other languages excluding - most notably - Lua), starts at 0.
In this case, what you want to be doing is this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HostScript : MonoBehaviour
{
void Update()
{
int randomInt = Random.Range(0, 2);
Debug.Log(randomInt);
}
}
Remember the max value is exclusive, so I’ve used 2, because now this will either output 0 or 1.
See how I’ve sent the random number straight into the print method? This will allow me to make my code much more readable, faster, and easier to write once I have multiple possible numbers (imagine if I waned my random number to be from 0 to 10,000! I would not want an if statement for every possibility).
If you only wanted your number temporarily, and don’t need it anywhere else in your Update() loop, you could even do Debug.Log(Random.Range(0, 2));
.
Hope this clears things up.
BTW, see the link for what you did in line 4:
https://stackoverflow.com/questions/505262/c-sharp-namespace-alias-whats-the-point