First of all, I really cannot understand why so many people do the same bad mistake all the time? The
Random
object should be created only once (per lifetime of the while application domain). I cannot understand what's the rationale behind that? Don't do it! At least move initialization of
randobj
out of the loop.
(I also cannot stop be amazed about using sub-string "obj" or "object" in the name of object, "app" or "application" in the name of application, "arr" or "array" in the name of array, etc. How can it even come to one's mind?!)
The object
randArray
makes no sense, whatsoever. The hard-coded
immediate constant is just amazing. And the loop…
Let's say you need four decimal digits. All you need is:
Random random = new Random();
int value = random.Next(10000);
—SA