I have read somewhere one of the main differences between Java and C++/C# is Java does something at Run-time and C# does something at compile-time. Is this true? If so could you explain this a bit more?
In C#, I created a function which takes in two inputs and returns a random number (called RandomNumber(int x, int y)
), using the Random Object. I then called this function twice in another function, expecting to get two difference values (two different random numbers). However, I kept getting same values, which baffled me, since I can do the same thing in Java and expect to get different numbers.
I then decided, to remove my function - RandomNumber(int x, int y) and call the Random inside my other function, show below.
Random random = new Random();
int randomNum;
int la;
randomNum = random.Next(1, 10);
numOne.Text = randomNum.ToString();
la = random.Next(1, 10);
This generates two different random numbers. Why is this the case?