I want to generate a list of random numbers with the shortest possible code.

Asked 1 years ago, Updated 1 years ago, 478 views

I'd like to use the list initialized with random numbers in Unity c#, but the current method will result in a long code as follows.
For me, who has become Python, it's very troublesome to write like this every time.

Is there any way to make a list of random numbers cleaner, preferably one line?

List<int>outputs=new List<int>();
foreach(intz_inEnumerable.Range(0,output))
{
    outputs.Add(Random.Range(0,wall_len));
}

c# unity3d random

2022-12-18 20:37

1 Answers

Enumerable.Range(0,output).Select(_=>Random.Range(0,wall_len))).ToList();


2022-12-18 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.