Non-Repetative Random Numbers as per Requirement.

In this article i will show you how can you get non-repetitive and fixed no of digit's random numbers as per your no of digit.there is lot's of methods are used for that.there is simple logic behind that. you can fix no of digit as per your requirement using this code.

We all know that many time we have requirement for get random numbers.there is lot's of method for create random can find it from google.
one of the most common method is here i give you,

Random rnd = new Random();
int s = rnd.Next(000000, 999999);

with using this code you can generate random number,but it will be repetitive.and if you want only 6 digit's random number then you can't get it from this code.

for get non repetitive and fixed no of digit's random code you have to use this method for that.

var char = "0123456789";
var random = new Random();
var result = new string(Enumerable.Repeat(char, i).Select(s => s[random.Next(s.Length)]).ToArray());

so,as per your requirement you can get non repetitive and fixed digit's random number with using this code,
if you want 5 digit's fixed random number then simply take i's value 5
so change i's value as per your requirement.
if you take i's value 5 then you get this results


I hope this will help you.

Ketan Italiya


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: