In python you can do something like this:
arr = list(set(randint(-50, 50) for _ in range(10)))
I do know how to program a extension method that fills a array, list or whatever you need with random values.
I find this cumbersome though, and I really admire how you can do it in python.
Although, I only know of Enumerable.Range,
which only can be used for generating fixed sequences, to my knowledge.
Is it possible in C# as well?
You could do like this:
Random rnd = new Random();
List<int> = Enumerable.Range(0,10).Select(n => rnd.Next(-50, 51)).ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With