Thursday, July 9, 2009

Random telephone number generator in C#?

i want to generate a random telephone number of the format XXX-XXX-XXXX using C# , the first 3 digits should not contain 8,9 and second 3 digits should not be more than number 742. please help

Random telephone number generator in C#?
For starters, you can use the built-in 'Random' class to generate the numbers you need, using the format below :





int RandomNumber = RandomClass.Next(4, 14);





This would generate a random number that is less than or equal to 14, and greater than or equal to 4.





Next, using this method, you will need to generate the 9 numbers you need, checking for all of the conditions you mentioned through a series of if statements, or similar conditional checks.





Then, once you have the 9 numbers, it should be relatively easy to create a string with them in the format you want.





Good luck.


No comments:

Post a Comment