Properties

mail@pastecode.io avatar
unknown
csharp
a month ago
1.7 kB
4
Indexable
Never
// Псевдоним
using UtilityRandom = Utility.Random;

// public
// private
// internal

internal class Program
{
	private static void Main(string[] args)
	{
		UtilityRandom random = new UtilityRandom();

		while (true)
		{
			Console.Clear();

			Console.WriteLine(random.RandomInt);
			Console.WriteLine(random.RandomDouble);
			Console.WriteLine(random.RandomFloat);
			Console.WriteLine(random.RandomBool);
			Console.WriteLine(random.RandomCharV1);
			Console.WriteLine(random.RandomCharV2);
			Console.WriteLine(random.RandomString);

			Thread.Sleep(500);
		}
	}
}

namespace Utility
{
	public class Random
	{
		public int RandomInt => new System.Random().Next();

		public float RandomFloat => new System.Random().NextSingle() * Single.MaxValue;

		public double RandomDouble => new System.Random().NextDouble() * Double.MaxValue;

		public bool RandomBool
		{
			get
			{
				System.Random random = new System.Random();

				bool result = (random.Next(2) == 0) ? true : false;

				return result;
			}
		}
		public char RandomCharV1
		{
			get
			{
				string characters = "qwertyuiopasdfghjklzxcvbnm";

				System.Random random = new System.Random();

				return characters[random.Next(characters.Length)];
			}
		}
		public char RandomCharV2
		{
			get
			{
				System.Random random = new System.Random();

				return (char)random.Next(97, 123);
			}
		}
		public string RandomString
		{
			get
			{
				string result = string.Empty;

				for (int i = 0; i < 10; i++)
				{
					result += RandomCharV2;
				}

				return result;
			}
		}

		//// Альтернатива: Auto-Property
		// public int RandomInt { get; set; }
	}
}
Leave a Comment