/// <summary> /// Returns a random lowercase character /// </summary> /// <returns>System.Char.</returns> public static char GetRandomSpecialCharacter() { var chars = @"!§$%&/()=_?#"; var randomNumber = IntHelpers.GetRandomNumber(chars.Length); return(chars[randomNumber]); }
/// <summary> /// Returns a random character /// </summary> /// <returns>System.Char.</returns> public static char GetRandomCharacter() { var chars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!§$%&/()=_?#1234567890"; var randomNumber = IntHelpers.GetRandomNumber(chars.Length); return(chars[randomNumber]); }
/// <summary> /// Returns a random uppercase character /// </summary> /// <returns>System.Char.</returns> public static char GetRandomUppercaseCharacter() { var chars = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var randomNumber = IntHelpers.GetRandomNumber(chars.Length); return(chars[randomNumber]); }
/// <summary> /// Returns a random lowercase character /// </summary> /// <returns>System.Char.</returns> public static char GetRandomLowercaseCharacter() { var chars = @"abcdefghijklmnopqrstuvwxyz"; var randomNumber = IntHelpers.GetRandomNumber(chars.Length); return(chars[randomNumber]); }
public async Task TestIfKeyIsProperlyStored() { var randomInt = IntHelpers.GetRandomNumber(100); await _redisService.SetAsync(RedisKeys.Default, randomInt); Assert.True(_redisService.Exist(RedisKeys.Default)); }
public IActionResult ShuffleIEnumerable(int number) { IEnumerable <int> list = Enumerable.Range(0, number) .Select(num => IntHelpers.GetRandomNumber(number * 2)); var shuffled = list.Shuffle(); return(Ok(new Tuple <IEnumerable <int>, IEnumerable <int> >(list, shuffled))); }
/// <summary> /// Gets a random element for the IEnumerable /// </summary> /// <typeparam name="T">Type of source IEnumerable</typeparam> /// <param name="source">Source IEnumerable collection</param> /// <returns>T.</returns> public static T GetRandomElement <T>(this IEnumerable <T> source) { // If the list is empty then return an empty instance of T if (source.IsEmpty()) { return(Activator.CreateInstance <T>()); } // Get a random number int randomNumber = IntHelpers.GetRandomNumber(source.Count() - 1); return(source.ElementAt(randomNumber)); }
public void VerifyThatShuffeDoesNotDeleteElements(int numberOfElements) { var originalList = Enumerable.Range(0, numberOfElements) .Select(num => IntHelpers.GetRandomNumber(1, numberOfElements)) .ToList(); var shuffledList = originalList.Shuffle().ToList(); var diff = originalList.Except(shuffledList).ToList(); Assert.True(diff.Count == 0); Assert.True(diff.IsEmpty()); Assert.True(originalList.Count == shuffledList.Count); }
public void TestRandomNumberInRange(int numberOfTests, int minValue, int maxValue) { List <int> randomNumbers = Enumerable.Range(0, numberOfTests) .Select(x => IntHelpers.GetRandomNumber(minValue, maxValue)) .ToList(); foreach (var randomNumber in randomNumbers) { Assert.True(randomNumber >= minValue && randomNumber <= maxValue); } var uniqueNumbers = randomNumbers.Distinct(); Assert.True(uniqueNumbers.Count() > 1); }
public IActionResult SortPerformance() { List <int> numbers = Enumerable.Range(0, 10000000) .Select(x => IntHelpers.GetRandomNumber(int.MaxValue)) .ToList(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); numbers.Sort(); stopwatch.Stop(); return(Ok(numbers)); }