Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- private static readonly Random rnd = new Random();
- private static void Main()
- {
- int numOfNumbers = 1000;
- for (int i = 0; i < numOfNumbers; i++)
- {
- Console.WriteLine($"Palindrome number {i}: {RandomPalindrome(100, 1000)}");
- }
- Console.ReadKey();
- }
- private static int RandomPalindrome(int min, int max)
- {
- int randomized;
- do
- {
- randomized = rnd.Next(min, max);
- } while (!randomized.IsPalindrome());
- return randomized;
- }
- }
- static class MethodExtensions
- {
- public static bool IsPalindrome(this int randomized)
- {
- int r, sum = 0, temp;
- temp = randomized;
- while (randomized > 0)
- {
- r = randomized % 10;
- sum = (sum * 10) + r;
- randomized /= 10;
- }
- if (temp == sum)
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement