public void MakeRandomSquare() { var randomPosition = RandomPicker.GetPosition(); var randomColor = RandomPicker.GetColor(); SpawnAt(randomPosition, randomColor); }
private void SetupPickingWeights(SelectionAlgorithm mode, List <T> solutions) { random = new RandomPicker <T>(); switch (mode) { case SelectionAlgorithm.FitnessProportional: foreach (var solution in solutions) { random.Add(solution, solution.GetFitness()); } break; case SelectionAlgorithm.Uniform: case SelectionAlgorithm.TournamentSelection: foreach (var solution in solutions) { random.Add(solution, 1); } break; case SelectionAlgorithm.RankProportional: for (int i = 0; i < solutions.Count; i++) { random.Add(solutions[i], i); } break; default: break; } }
private static void TestRandomPicker() { var items = new List <RandomItem <string> > { new RandomItem <string>(0.6, "a"), new RandomItem <string>(0.1 / 3, "b"), new RandomItem <string>(0.1 / 3, "c"), new RandomItem <string>(0.1 / 3, "d"), new RandomItem <string>(0.3, "e") }; var rp = new RandomPicker <string>(items, 1337); var dict = new Dictionary <string, int>(); for (var i = 0; i < 10000; i++) { var pick = rp.Pick(); if (!dict.ContainsKey(pick.Item)) { dict[pick.Item] = 1; } else { dict[pick.Item]++; } } foreach (var i in dict) { Console.WriteLine(i.Key + ": " + i.Value); } }
public static DrawAction <T> PickRandom <T>(out RandomPicker <T> picker) { picker = new RandomPicker <T>(); DrawAction <T> f = picker.DrawingAction; return(f); }
public bool TryRandAskNpc(int npcId, out int newRank, out int newNpcId) { newRank = MINAskRank; newNpcId = MINAskNpc; ConfigSkillcardaskrankEntity npc; if (!TryGetAskNPC(npcId, out npc)) { return(false); } int askRank = npc.AskRank; if (askRank >= MAXAskRank) { return(true); } int succVal = Convert.ToInt32(npc.SuccRate * 10000); if (RandomPicker.RandomInt(1, 10000) > succVal) { return(true); } newRank = askRank + 1; return(TryRandAskNpc_Rank(newRank, out newNpcId)); }
/// <summary> /// 踢球状态 /// </summary> /// <param name="shootProp"></param> /// <returns></returns> ShootItem GetShootResult(int shootProp) { var rand = RandomPicker.GetRandom(); var obj = new ShootItem(); int val = RandomPicker.RandomInt(0, 100, rand); if (val <= _aDRateShootFly) { obj.ShootPos = 2;//射飞 } else if (val <= _aDRateShootFrame) { obj.ShootPos = 1;//射中门框 } else { obj.ShootPos = 0;//射中 } bool diveSame = val <= _aDRateDiveSame; obj.DiveDir = diveSame; if (obj.ShootPos == 0) { if (!diveSame || RandomPicker.RandomInt(1, 100) <= shootProp * 100 / (shootProp + 200)) { obj.IsGoals = true; return(obj); } } obj.IsGoals = false; return(obj); }
public static void Main(string[] args) { List <string> liststr = new List <string>(); RandomPicker.passaNomes(liststr); List <string> listShuffled = Shuffle(liststr); Console.WriteLine("\n"); listShuffled.ForEach(Console.WriteLine); }
public bool TryRandSkillCode(int skillClass, int skillLevel, out string skillCode) { skillCode = string.Empty; int libKey = CastLibKey(skillClass, skillLevel); List <string> lib = null; if (!s_dicSkillLib.TryGetValue(libKey, out lib) || lib.Count == 0) { return(false); } skillCode = lib[RandomPicker.RandomInt(0, lib.Count - 1)]; return(true); }
public ActionResult WheelOfFortune(FormCollection collection) { int bet = collection["Bet"].AsInt(); GameResult result = new GameResult(); var items = new List <RandomItem <ISpinAction> > { new RandomItem <ISpinAction>(0.6, new BetMultiplier(0.5m)), new RandomItem <ISpinAction>(0.2, new BetMultiplier(1.1m)), new RandomItem <ISpinAction>(0.1, new BetMultiplier(0m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(1.5m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(2m)), new RandomItem <ISpinAction>(0.1 / 3, new BetMultiplier(3m)) }; Random rand = new Random(); var rp = new RandomPicker <ISpinAction>(items, rand.Next()); //TODO: rand.next gives the same order for each player, would be better to have a different order for each player var user = HttpContext.User.Identity as ClaimsIdentity; var userId = user.GetUserId(); using (var anacondaModel = new AnacondaModel()) { WalletDAO walletDAO = new WalletDAO(anacondaModel); if (walletDAO.Pay(userId, bet)) { result = rp.Pick().Item.Execute(new GameContext(bet)); } else { result = new GameResult() { Bet = bet, CreditsGained = 0, Status = ResultStatus.InsufficientCredits }; } var wallet = anacondaModel.Wallets.First(u => u.UserId == userId); wallet.Credits += result.CreditsGained; anacondaModel.SaveChanges(); } ViewBag.Bet = bet; return(View(result)); }
//methods public Task Insert <TEntity>(List <TEntity> entities) where TEntity : class { List <TEntity> newList = new List <TEntity>(); foreach (TEntity item in entities) { bool drop = RandomPicker.NextBoolean(_dropOutChance); if (drop) { continue; } newList.Add(item); } return(_persistentStorage.Insert(newList)); }
static UserAgent() { pc = new string[16] { "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1", "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1", "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11", "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)" }; mob = new string[13] { "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5", "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5", "Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5", "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", "MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", "Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10", "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13", "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+", "Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0", "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124", "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)", "UCWEB7.0.2.37/28/999", "Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999" }; pcPicker = new RandomPicker <string>(); pcPicker.Update(new List <string>(pc)); mobPicker = new RandomPicker <string>(); mobPicker.Update(new List <string>(mob)); }
public bool TryRandAskSkillCode(int npcId, out string skillCode) { skillCode = string.Empty; RandomPicker picker = null; if (!TryGetAskPicker(npcId, out picker)) { return(false); } var pickObj = picker.PickRandom(); if (null == pickObj) { return(false); } if (pickObj.Index == 0) { return(true); } return(TryRandSkillCode(pickObj.Index, pickObj.Index2, out skillCode)); }
public string RandomPickPublicServiceUrl(Dictionary <string, List <string> > remoteServices, string serviceName) { var publicUrl = ""; List <string> serviceList = null; if (remoteServices != null && remoteServices.TryGetValue(serviceName, out serviceList)) { if (serviceList != null && serviceList.Count > 0) { var remoteInfoParts = RandomPicker.Pick <string>(serviceList).Split('|'); if (remoteInfoParts.Length >= 2) // name | url | key { var urls = remoteInfoParts[1].Split(','); if (urls.Length >= 2) { publicUrl = urls[1]; } } } } return(publicUrl); }
public List <SlotItem> GetRandomColumnFruit(Random rand) { var items = new List <RandomItem <SlotItem> > { new RandomItem <SlotItem>(0.15, new SlotItem("Banana", 0.5)), new RandomItem <SlotItem>(0.15, new SlotItem("Apple", 0.4)), new RandomItem <SlotItem>(0.1, new SlotItem("Gold", 1)), new RandomItem <SlotItem>(0.2, new SlotItem("Kiwi", 0.25)), new RandomItem <SlotItem>(0.2, new SlotItem("Raspberry", 0.2)), new RandomItem <SlotItem>(0.2, new SlotItem("Strawberry", 0.15)) }; var randomPicker = new RandomPicker <SlotItem>(items, rand.Next()); List <SlotItem> slotItems = new List <SlotItem>(); for (int i = 0; i < 3; i++) { slotItems.Add(randomPicker.Pick().Item); } return(slotItems); }
public bool TryGetAskPicker(int npcId, out RandomPicker picker) { s_dicAskRand.TryGetValue(npcId, out picker); return(null != picker); }
public void PickRandomEnum_NotNull() { var actual = RandomPicker.PickRandomEnum <Gender>().ToString(); Assert.NotNull(actual); }
public void PickRandomEnum_NotEmpty() { var actual = RandomPicker.PickRandomEnum <FileName>().ToString(); Assert.NotEmpty(actual); }