Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to convert random(L) in JAVA into Random(int32) in C#
How to convert random(L) in JAVA into Random(int32) in C#

Just convert a Java program into C# and ultimately achieve the same result. If you are a little more stubborn, there is no problem in requiring the same algorithm. But it is a bit too much to require that the C# code and the ava code are exactly the same, with the same data types and the same punctuation marks. Should be more flexible, right? Don’t you programmers all claim to be smart and able to draw inferences from one example to another?

The following is a piece of java code, see how it can be converted to C# code

Date dt = new Date();

Random rand = new Random( dt.getTime());

n = rand.nextInt();

The following is converted into C# code.

Random rand = new Random();//See CSDN explanation below

rand.Next();

CSDN explanation:

Random() Initializes a new instance of the Random class using a default time-related seed value.

Random(Int32) Initializes a new instance of the Random class using the specified seed value.

In this default Random() constructor, the default seed value related to time is used, which is actually similar to using the java code Date dt = new Date();dt.getTime(); as the seed . The effect is the same. You can save a few lines of code and parameters by using C# compared to Java.