public Dismissal(Bowler bowler, Team team, IRandomNumberGenerator rand) { _bowler = bowler.Name(); _caughtBy = ""; var randomNumber = rand.GetRandomNumber(0, 100); if (randomNumber <= 30) { _howOut = dismissals[0]; } if (randomNumber > 31 & randomNumber <= 60) { _caughtBy = team.GetPlayer(rand.GetRandomNumber(0, team.NumberPlayers())); _howOut = dismissals[1]; } if (randomNumber > 60 & randomNumber <= 80) { _howOut = dismissals[2]; } if (randomNumber > 80 & randomNumber <= 90) { _howOut = dismissals[3]; } if (randomNumber > 90 & randomNumber <= 100) { _howOut = dismissals[4]; } }
public string GetFortune() { var fortunes = _fortuneRepository.GetFortunes("good"); int randomNumber = _randomNumberGenerator.GetRandomNumber(0, fortunes.Length); return(fortunes[randomNumber]); }
public string GetId(string name, string postfix) { var normalizeName = name .Replace('&', '_') .Replace('%', '_') .Replace('.', '_') .Replace(' ', '_') .Replace('-', '_') .Replace('+', '_') .Replace('·', '_') .Replace("___", "_") .Replace("__", "_") .Replace("(", string.Empty) .Replace(")", string.Empty) .Replace("[", string.Empty) .Replace("]", string.Empty) .Replace("{", string.Empty) .Replace("}", string.Empty); if (normalizeName.Length > 40) { normalizeName = normalizeName.Substring(0, 40); } return(string.Concat(new object[] { "Id_" + normalizeName, "_", _randomNumberGenerator.GetRandomNumber(), "_", postfix })); }
public IHttpActionResult GetRandomFood() { try { IEnumerable <FoodItem> foodItems = _foodRepository.GetAll(x => x.IsPublic, includeProperties: "FoodList").AsEnumerable(); if (!foodItems.Any()) { return(NotFound()); } IEnumerable <FoodItem> enumerable = foodItems as IList <FoodItem> ?? foodItems.ToList(); FoodItem elementAt = enumerable.ElementAt(_randomNumberGenerator.GetRandomNumber(enumerable.Count())); if (elementAt == null) { return(NotFound()); } return(Ok(Mapper.Map <FoodItemViewModel>(elementAt))); } catch (Exception exception) { return(InternalServerError(exception)); } }
public virtual outcomes Bowl() { Array values = Enum.GetValues(typeof(outcomes)); int index = _rand.GetRandomNumber(0, values.Length - 1); return((outcomes)values.GetValue((int)index)); }
public outcomes Play(outcomes outcome) { int flipCoin = _rand.GetRandomNumber(0, 2); if (flipCoin == 1) { return(outcome); } return(outcomes.NO_RUNS); }
public override async Task <GetWordResponse> Handle(GetWordRequest request, CancellationToken cancellationToken) { var word = string.Empty; while (word.Length < request.MinimumLength) { word = await wordDictionaryService .GetWordAtLineIndexFromDictionary( FileExtensions.GetFile(applicationSettings.DictionaryPath), randomNumberGenerator .GetRandomNumber(General.MaximumDictionaryLineIndex)); } return(Success(word)); }
public IActionResult GetRandomFood() { IEnumerable <FoodItem> foodItems = _foodRepository.GetAllPublic(); if (!foodItems.Any()) { return(BadRequest("No Items Found")); } FoodItem elementAt = foodItems.ElementAt(_randomNumberGenerator.GetRandomNumber(foodItems.Count())); if (elementAt == null) { return(NotFound()); } return(Ok(Mapper.Map <FoodItemDto>(elementAt))); }
public string Scramble(string value) { var scrambledWord = string.Empty; var usedIndexList = new List <int>(); while (scrambledWord.Length < value.Length) { var index = randomNumberGenerator.GetRandomNumber(value.Length); var nextCharacter = GetCharacterAtIndex(value, index); if (!usedIndexList.Contains(index)) { scrambledWord += nextCharacter; usedIndexList.Add(index); } } return(scrambledWord); }
public Outcome(IRandomNumberGenerator rand) { var result = rand.GetRandomNumber(0, 133); if (result > 0 & result < 58) { this.runs = 0; } if (result >= 58 & result <= 81) { this.runs = 1; } if (result >= 82 & result <= 88) { this.runs = 2; } if (result == 89) { this.runs = 3; } if (result >= 90 & result <= 96) { this.runs = 4; } if (result >= 97 & result <= 98) { this.runs = 6; } if (result >= 99 & result <= 100) { this.runs = 0; this.wicket = true; } if (result > 100 & result <= 104) { this.runs = 1; this.noBall = true; this.wicket = false; } if (result > 104 & result <= 108) { this.runs = 1; this.wides = 1; this.wicket = false; } if (result == 109) { this.runs = 2; this.wides = 2; this.wicket = false; } if (result == 110) { this.runs = 3; this.wides = 3; this.wicket = false; } if (result > 110 & result <= 113) { this.runs = 4; this.wides = 4; this.wicket = false; } if (result > 113 & result <= 118) { this.runs = 1; this.byes = 1; this.wicket = false; } if (result == 120) { this.runs = 2; this.byes = 2; this.wicket = false; } if (result == 121) { this.runs = 3; this.byes = 3; this.wicket = false; } if (result > 121 & result <= 125) { this.runs = 4; this.byes = 4; this.wicket = false; } if (result > 125 & result <= 127) { this.runs = 1; this.legByes = 1; this.wicket = false; } if (result == 128) { this.runs = 2; this.legByes = 2; this.wicket = false; } if (result == 129) { this.runs = 3; this.legByes = 3; this.wicket = false; } if (result > 129 & result <= 133) { this.runs = 4; this.legByes = 4; this.wicket = false; } // Takes Event and creates outcome and returns // TODO Map events in Cricket and probability // 58% of balls are dot balls // 24% of balls are 1s // 7% are 2s // 2% are hit for six // 7% are fours // 1% are threes // 3% are dismissals }
public int SeedNumber() { CurrentNumber = _randomNumberGenerator.GetRandomNumber(); _previousNumbers.Add(CurrentNumber); return(CurrentNumber); }
public IActionResult Index() { ViewData["randomNumber"] = _randomNumberGenerator.GetRandomNumber(); return(View()); }
/// <summary> /// Get a random char inside a char array using the IRandomNumberGenerator instance /// </summary> /// <param name="dictionary"></param> /// <returns></returns> internal virtual char GetRandomChar(IList <char> dictionary) { this.ThrowIfDisposed(); return(dictionary[_rng.GetRandomNumber(0, dictionary.Count)]); }
public void CallGetRandomNumber() { RandomNumberResult = _randomNumberGenerator.GetRandomNumber(); }