Linked Questions
25 questions linked to/from How do I seed a random class to avoid getting duplicate random values
848 votes
15 answers
253k views
Random number generator only generating one random number
I have the following function: //Function to get random number public static int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); } How I call it: ...
0 votes
0 answers
64 views
C# generating a random number, returns the same result each time [duplicate]
For a school assignment I am currently working on a small project involving a console application. it fills a grid with random traffic objects (like bicycles and cars). Every time a traffic object is ...
8 votes
2 answers
6k views
Seeding Multiple Random Number Generators
I have recently been discussing the initialisation of multiple random number generators of the same type in the comments of another post and in that discussion we asked the following questions: 1) Is ...
2 votes
2 answers
8k views
How to randomize seed in C# [duplicate]
I need to generate random int in C#. I am using clock time to set the seend. However, as the rnd.Next() function may take less than a millisecond, this does not work if one has to generate a list of ...
2 votes
6 answers
375 views
Best way to distribute different outcomes?
I have a method called "GetValue()" which is supposed to return the value "A", "B", "C" or "D" on each method call. I want this method to return the value "A" in 30% of the method calls and the value ...
4 votes
4 answers
2k views
System.Random default constructor system clock resolution?
I have several processes in which I use System.Random's default constructor to generate random numbers. I read about it on MSDN but it dosn't say the specific system clock resolution it uses, for ...
2 votes
3 answers
401 views
Random number behaves weird, not fully random
In my .NET game my rand function that are determining how much damage each out of the players five characters should take, however the 1st one always seems to be at the bottom of the scale and the ...
1 vote
2 answers
3k views
TestCaseSource in N-Unit
I'm writing some N-Unit tests and I'm having a little difficulty. I'm trying to wire up a Test to a TestCaseSource in my code, but it doesn't seem to be constructing the objects correctly. Here is my ...
5 votes
4 answers
180 views
How do I have two randoms in a row give different values?
For example, if I have a class: public class Class { public Random r; public Class() {r= new Random()} } and later create two instances of it: Class a = new Class(); Class b = new Class(); and call ...
1 vote
2 answers
2k views
Run random number with each assertion in a unit test
I am creating a unit test that will test company information into the system but so I can test various assertions in my test. Here is the code I wrote: public static Random randnum = new Random(); ...
1 vote
4 answers
1k views
Cannot reference public object in another class, please look at my source and let me know what I'm doing wrong
I'm learning C# and I'm currently playing with Monogame. What I'm trying to do is declare a public instance of the System.Random class called "randVar" in my Game1 class and then access it from my ...
0 votes
1 answer
1k views
hiding a message in rgb colored pixels
I've written some code, it's just an experiment. I had an idea (probably has been done before) to create a random image and set pixels rgb values at random locations to an ascii character number in ...
1 vote
2 answers
166 views
Possible Reasons for Stack Overflow
I have the following C# code which fills an ArrayList with Random numbers between 1 to 30. I have to call this function 25 times. My code: private void getNextTrack() { int ...
1 vote
2 answers
718 views
Generating numbers in C# but skipping ones which meet certain criteria?
So I'm building a small math game where random sums are generated and, upon being answered, added to either a right or wrong score. It's going well, and I've received some help with certain things and ...
3 votes
1 answer
285 views
Is The Following VB.NET Implementation Of Random Thread-Safe?
I know there are many thread-safety questions especially regarding the Random class in VB.NET and C#. I've read through several as well as a blog post from Jon Skeet (https://codeblog.jonskeet.uk/2009/...