当前位置: 首页>>代码示例>>C#>>正文


C# List.Shuffle方法代码示例

本文整理汇总了C#中List.Shuffle方法的典型用法代码示例。如果您正苦于以下问题:C# List.Shuffle方法的具体用法?C# List.Shuffle怎么用?C# List.Shuffle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在List的用法示例。


在下文中一共展示了List.Shuffle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetHintStrings

        /// <summary>
        /// Gets available hint strings
        /// </summary>
        /// <remarks>Adapted from vimium to give a consistent experience, see https://github.com/philc/vimium/blob/master/content_scripts/link_hints.coffee </remarks>
        /// <param name="hintCount">The number of hints</param>
        /// <returns>A list of hint strings</returns>
        public IList<string> GetHintStrings(int hintCount)
        {
            var hintCharacters = new[] { 's', 'a', 'd', 'f', 'j', 'k', 'l', 'e', 'w', 'c', 'm', 'p', 'g', 'h' };
            var digitsNeeded = (int)Math.Ceiling(Math.Log(hintCount) / Math.Log(hintCharacters.Length));

            var shortHintCount = Math.Floor((Math.Pow(hintCharacters.Length, digitsNeeded) - hintCount) / hintCharacters.Length);
            var longHintCount = hintCount - shortHintCount;

            var hintStrings = new List<string>();

            if (digitsNeeded > 1)
            {
                for (var i = 0; i < shortHintCount; ++i)
                {
                    hintStrings.Add(NumberToHintString(i, hintCharacters, digitsNeeded - 1));
                }
            }

            var start = (int)(shortHintCount * hintCharacters.Length);
            for (var i = start; i < (start + longHintCount); ++i)
            {
                hintStrings.Add(NumberToHintString(i, hintCharacters, digitsNeeded));
            }

            // Note that shuffle is lazy evaluated. Sigh.
            return hintStrings.Shuffle().ToList();
        }
开发者ID:arizzubair,项目名称:hunt-and-peck,代码行数:33,代码来源:HintLabelService.cs

示例2: AddWords

        public void AddWords(params string[] words)
        {
            //var placers = new List<WordPlacers.WordPlacer>{new WordPlacers.Diagonal(),
            //                                               new WordPlacers.Vertical(),
            //                                               new WordPlacers.Horizontal(),
            //                                               new WordPlacers.Reversed(new WordPlacers.Diagonal()),
            //                                               new WordPlacers.Reversed(new WordPlacers.Vertical()),
            //                                               new WordPlacers.Reversed(new WordPlacers.Horizontal()),
            //                                               };

            var placers = new List<WordPlacers.WordPlacer> { new WordPlacers.Horizontal() };

            foreach (var currentWord in words)
            {
                placers.Shuffle();

                foreach (var placer in placers)
                {
                    var result = placer.TryPlaceWord(currentWord, this);
                    if(result!=null)
                    {
                        Console.WriteLine("placed $result->word with {$result->direction} at X:{$result->x} Y:{$result->y}<br/>");
                        break;
                    }
                }
            }
        }
开发者ID:blueboxes,项目名称:Word-Search-Builder,代码行数:27,代码来源:WordSearch.cs

示例3: Randomize

        public void Randomize(Patch patch, Random r)
        {
            // Create list of default teleporter position values
            List<byte[]> coords = new List<byte[]>
            {
                new byte[]{ 0x20, 0x3B }, // Teleporter X, Y (top-left)
                new byte[]{ 0x20, 0x7B },
                new byte[]{ 0x20, 0xBB },
                new byte[]{ 0x70, 0xBB },
                new byte[]{ 0x90, 0xBB },
                new byte[]{ 0xE0, 0x3B },
                new byte[]{ 0xE0, 0x7B },
                new byte[]{ 0xE0, 0xBB }
            };

            // Randomize them
            coords.Shuffle(r);

            // Write the new x-coordinates
            for (int i = 0; i < coords.Count; i++)
            {
                byte[] location = coords[i];
                patch.Add((int)(EMiscAddresses.WarpXCoordinateStartAddress + i), location[0], String.Format("Teleporter {0} X-Pos", i));
            }

            // Write the new y-coordinates
            for (int i = 0; i < coords.Count; i++)
            {
                byte[] location = coords[i];
                patch.Add((int)(EMiscAddresses.WarpYCoordinateStartAddress + i), location[1], String.Format("Teleporter {0} Y-Pos", i));
            }

            // These values will be copied over to $04b0 (y) and $0470 (x), which will be checked
            // for in real time to determine where Mega will teleport to
        }
开发者ID:duckfist,项目名称:MM2Random,代码行数:35,代码来源:RTeleporters.cs

示例4: GetDayActivity

        public IList<string> GetDayActivity(IList<string> zoo, string killer)
        {
            if (!zoo.Contains(killer))
            {
                return new List<string>();
            }

            var herring = new List<string>(GameResources.Herrings);
            var goodTraits = new List<string>(GameResources.GoodTraits);
            var badTraits = new List<string>(GameResources.BadTraits);
            herring.Shuffle();
            goodTraits.Shuffle();
            badTraits.Shuffle();

            // good and bad traits
            int badIndex = 0;
            int goodIndex = 0;
            var clues = zoo.Select(x =>
                                {
                                    double chance = x == killer ? ChanceBadKillerTrait : ChanceBadFodderTrait;
                                    string trait = Extensions.RandomGenerator.Next(0, 999)/1000.0 < chance
                                        ? badTraits[badIndex++]
                                        : goodTraits[goodIndex++];
                                    return String.Format(trait, x);
                                }).ToList();

            // herrings
            int herringIndex = 0;
            clues.AddRange(zoo.Select(x => String.Format(herring[herringIndex++], x)));

            clues.Shuffle();

            return clues;
        }
开发者ID:mprofGamesDev-Dreams,项目名称:zooDoneIt,代码行数:34,代码来源:ClueManager.cs

示例5: DataHolder

        public DataHolder()
        {
            phrases = new List<Phrase> ();

            phrases.Add (new Phrase ("USP", false));
            phrases.Add (new Phrase ("Micro services", false));
            phrases.Add (new Phrase ("Win-Win", false));
            phrases.Add (new Phrase ("Time to market", false));
            phrases.Add (new Phrase ("Perfor-mance", false));
            phrases.Add (new Phrase ("Scalable", false));
            phrases.Add (new Phrase ("Portfolio", false));
            phrases.Add (new Phrase ("24/7", false));
            phrases.Add (new Phrase ("New econo-my", false));
            phrases.Add (new Phrase ("Niche", false));
            phrases.Add (new Phrase ("Upside", false));
            phrases.Add (new Phrase ("Revenue", false));
            phrases.Add (new Phrase ("Supply chain", false));
            phrases.Add (new Phrase ("Call", false));
            phrases.Add (new Phrase ("Web 2.0", false));
            phrases.Add (new Phrase ("The new Face-book", false));
            phrases.Add (new Phrase ("Market share", false));
            phrases.Add (new Phrase ("Stake-holder", false));
            phrases.Add (new Phrase ("Inves-tors", false));
            phrases.Add (new Phrase ("VC", false));
            phrases.Add (new Phrase ("Burn rate", false));
            phrases.Add (new Phrase ("Work group", false));
            phrases.Add (new Phrase ("Market leader", false));
            phrases.Add (new Phrase ("Work load", false));
            phrases.Add (new Phrase ("Work-Life balance", false));

            phrases.Shuffle ();

            Current = this;
        }
开发者ID:pavlinap,项目名称:BullshitBingo,代码行数:34,代码来源:DataHolder.cs

示例6: CreateRandomRound

        public static SuggestedTournamentRound CreateRandomRound(List<Player> players)
        {
            players.Shuffle();
            var round = new SuggestedTournamentRound();

            var playersSittingOut = CalculatePlayersSittingOutNext(players);
            round.AddPlayersSittingOut(playersSittingOut);
            var playingPlayers = players.Except(playersSittingOut).ToList();
            List<Player> remainingPlayers;
            var match = SuggestedMatch.CreateMatchFromFirstFirstFourPlayers(playingPlayers, out remainingPlayers);
            while (match != null)
            {
                round.AddMatch(match);
                playingPlayers = remainingPlayers;
                match = SuggestedMatch.CreateMatchFromFirstFirstFourPlayers(playingPlayers, out remainingPlayers);

            }

            if (remainingPlayers.Count != 0)
            {
                throw new Exception("Was not expecting any remainig players!");
            }

            return round;
        }
开发者ID:mikeparker,项目名称:tournamentmatching,代码行数:25,代码来源:SuggestedTournamentRound.cs

示例7: Build

        public Level Build(int dimension)
        {
            if (dimension == 0)
                return _Level;
            var mapCells = LevelGenerator._BuildMaze(dimension);
            var rooms = new List<MazeCell>();
            var aisles = new List<MazeCell>();
            foreach (var cell in mapCells)
            {
                var walls = cell.Walls;
                var center = cell.GetPosition(_Width, _Height);
                foreach (var wall in walls)
                {
                    var dir = _WallToDirection(wall);
                    _Level.Add(new LevelUnit(Data.LEVEL_UNIT.WALL , center, dir));
                }

                if (cell.IsRoom())
                {
                    rooms.Add(cell);
                }
                else if (cell.HaveWall())
                {
                    aisles.Add(cell);
                }
            }

            _BuildScene(rooms.Shuffle().ToArray(), aisles.Shuffle().ToArray());

            return _Level;
        }
开发者ID:jiowchern,项目名称:ItIsNotAGame1-Backend,代码行数:31,代码来源:LevelGenerator.cs

示例8: GetMove

        public List<Square> GetMove(Square square)
        {
            var movesList = new List<Square>();

            var move = HorizontalLeftUp(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = HorizontalLeftDown(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = HorizontalRightUp(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = HorizontalRightDown(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = VerticalUpLeft(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = VerticalUpRight(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = VerticalDownLeft(square);
            if (IsSquareValid(move)) movesList.Add(move);

            move = VerticalDownRight(square);
            if (IsSquareValid(move)) movesList.Add(move);

            movesList.RemoveAll(Visited);

            // randomize the order of a list to provide various detours each time
            movesList.Shuffle();

            return movesList;
        }
开发者ID:floring,项目名称:KnightsTourProblem,代码行数:35,代码来源:KnightMove.cs

示例9: PartitionUsersAndItems

        /// <summary>Partition dataset user- and item-wise for parallel processing</summary>
        /// <remarks>
        /// Literature:
        /// <list type="bullet">
        ///   <item><description>
        ///     Rainer Gemulla, Peter J. Haas, Erik Nijkamp, Yannis Sismanis:
        ///     Large-Scale Matrix Factorization with Distributed Stochastic Gradient Descent.
        ///     KDD 2011.
        ///     http://www.mpi-inf.mpg.de/~rgemulla/publications/gemulla11dsgd.pdf
        ///   </description></item>
        /// </list>
        /// </remarks>
        /// <returns>a two-dimensional array of index lists, each entry corresponds to one block entry</returns>
        /// <param name='dataset'>a feedback dataset</param>
        /// <param name='num_groups'>the number of groups both users and items are partitioned into</param>
        public static IList<int>[,] PartitionUsersAndItems(this IDataSet dataset, int num_groups)
        {
            // divide rating matrix into blocks
            var user_permutation = new List<int>(Enumerable.Range(0, dataset.MaxUserID + 1));
            var item_permutation = new List<int>(Enumerable.Range(0, dataset.MaxItemID + 1));
            user_permutation.Shuffle();
            item_permutation.Shuffle();

            var blocks = new IList<int>[num_groups, num_groups];
            for (int i = 0; i < num_groups; i++)
                for (int j = 0; j < num_groups; j++)
                    blocks[i, j] = new List<int>();

            for (int index = 0; index < dataset.Count; index++)
            {
                int u = dataset.Users[index];
                int i = dataset.Items[index];

                blocks[user_permutation[u] % num_groups, item_permutation[i] % num_groups].Add(index);
            }

            // randomize index sequences inside the blocks
            for (int i = 0; i < num_groups; i++)
                for (int j = 0; j < num_groups; j++)
                    blocks[i, j].Shuffle();

            return blocks;
        }
开发者ID:pipifuyj,项目名称:MyMediaLite,代码行数:43,代码来源:MultiCore.cs

示例10: GenerateStartDeck

        private static List<Card> GenerateStartDeck()
        {
            List<Card> startDeck = new List<Card>();
            startDeck.AddRange(GetCardsOfType(54, CardType.Hero, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.ElementalAura, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.PowerAura, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.ShadowAura, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.LightAura, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.TimeAura, true));
            startDeck.AddRange(GetCardsOfType(15, CardType.SkillAura, true));
            startDeck.AddRange(GetCardsOfType(171, CardType.Action, false));
            startDeck.AddRange(GetCardsOfType(108, CardType.Item, true));
            startDeck.AddRange(GetCardsOfType(100, CardType.Spell, true));
            startDeck.AddRange(GetCardsOfType(60, CardType.Quest, false));
            startDeck.AddRange(GetCardsOfType(8, CardType.Boss, false));
            startDeck.AddRange(GetCardsOfType(15, CardType.Mercenary, false));
            startDeck.AddRange(GetCardsOfType(15, CardType.Mercenary, false));
            startDeck.Add(new Slime());
            startDeck.Add(new Slime());
            startDeck.Add(new Slime());
            startDeck.Add(new Slime());
            startDeck.Add(new CaptainFalcon());

            startDeck.Shuffle();

            return startDeck;
        }
开发者ID:GLOOGO,项目名称:MyGame,代码行数:27,代码来源:MasterDecks.cs

示例11: GetListOfChromosomsUsinRuletteMethod

        private List<Chromosom> GetListOfChromosomsUsinRuletteMethod(List<Chromosom> population)
        {
            double sumOfAllChromosomsFitnessValues = population.Sum(x => x.SurivatePoints);
            double meanOfChromosomsFitnessValues = sumOfAllChromosomsFitnessValues / population.Count;

            List<Chromosom> tmpPopulation = new List<Chromosom>(population.Count);

            foreach (var chromosom in population)
            {
                int numberOfChromosomsInNewGeneration = (int)Math.Round(chromosom.SurivatePoints / meanOfChromosomsFitnessValues);
                Console.WriteLine("Chomosom: {0} is going to be add {1}-times to new generation", chromosom, numberOfChromosomsInNewGeneration);
                for (int i = 0; i < numberOfChromosomsInNewGeneration; i++)
                {
                    tmpPopulation.Add(chromosom);
                }
            }

            int countDiffence = tmpPopulation.Count - population.Count;
            
            if (countDiffence < 0 )
            {
                var sortedPopulation = population.OrderByDescending(chromosom => chromosom.SurivatePoints);
                tmpPopulation.AddRange(sortedPopulation.Take(Math.Abs(countDiffence)));
            }
            else if (tmpPopulation.Count - population.Count > 0)
            {
                tmpPopulation = tmpPopulation.Shuffle().Take(population.Count).ToList();
            }

            return tmpPopulation;
            // do cross
        }
开发者ID:laikkk,项目名称:io.genetic-algorithm,代码行数:32,代码来源:GeneticAlgorytm.cs

示例12: Mutate

        public void Mutate(Genotype genotype, MutationResults results)
        {
            var neuronIndexA = Random.Range(0, genotype.NeuronCount);
              var neuronGeneA = genotype.NeuronGenes.ElementAt(neuronIndexA);

              var candidates = new List<NeuronGene>(genotype.NeuronGenes);
              candidates.Shuffle();

              NeuronGene neuronGeneB = default(NeuronGene);
              bool foundNeuron = false;
              for (var i = 0; i < candidates.Count; i++) {
            neuronGeneB = candidates[i];

            var exists = genotype.SynapseGenes.Any(s =>
              neuronGeneA.InnovationId == s.fromNeuronId &&
              neuronGeneB.InnovationId == s.toNeuronId);

            if (!exists) {
              foundNeuron = true;
              break;
            }
              }

              if (foundNeuron) {
            var synapseInnovationId = innovations.GetSynapseInnovationId(neuronGeneA.InnovationId, neuronGeneB.InnovationId);
            var synapseGene = new SynapseGene(synapseInnovationId, neuronGeneA.InnovationId, neuronGeneB.InnovationId, true);

            var synapseGenes = new GeneList<SynapseGene>(genotype.SynapseGenes);
            synapseGenes.Add(synapseGene);
            genotype.SynapseGenes = synapseGenes;

            results.addedSynapses += 1;
              }
        }
开发者ID:BarkingMouseStudio,项目名称:unity-experiments,代码行数:34,代码来源:AddSynapseMutator.cs

示例13: CharacterGen

	public static LGcharacter CharacterGen () 
	{
		LGcharacter Baby = LGcharacter.CreateInstance<LGcharacter>();
		List<int> toGen = new List<int>();
		List<int> lastPass = new List<int> ();
		for (int i = 0; i < (int)TraitType.COUNT; i++) {
			Baby.SetTrait ((TraitType)i, kMinTrait);
			toGen.Add (i);
		}
		toGen.Shuffle ();
		int toSpend = kMaxGenPoints;
		while (toGen.Count > 0) {
			TraitType type = (TraitType)toGen [0];
			lastPass.Add (toGen [0]);
			toGen.RemoveAt (0);
			double gaussRoll = RNGesus.PraiseGauss (kMeanTrait, kTraitDev);
			int newVal = (int)gaussRoll;
			if (newVal > kMaxTrait-1) {
				newVal = kMaxTrait-1;
			}
			if (newVal < kMinTrait) {
				newVal = kMinTrait;
			}
			if (newVal > toSpend) {
				newVal = toSpend;
			}
			if (Baby.AddTrait (type, newVal)) {
				toSpend -= newVal;
			}
		}
		// Do one last pass to spend remaining points randomly.
		// Removing stats that are too full. 
		// TODO: Instead, spend these on specialized traits based on the number of unspent points
		/*
		while (toSpend > 0 && lastPass.Count > 0) {
			int roll = RNGesus.Praise (0, lastPass.Count-1);
			if (Baby.AddTrait ((TraitType)lastPass[roll], 1)) {
				toSpend--;
			} else {
				lastPass.RemoveAt (roll);
			}
		}
		*/
		// Set stats to their default values (max for most, min for Toxicity)
		for (int i = 0; i < (int)StatusType.COUNT; i++) {
			Baby.SetStat ((StatusType)i, kMaxStatus);
		}
		Baby.SetStat (StatusType.TOXICITY, kMinStatus);

		// Roll Random Skills
		Dictionary<uint, LGskill> genSkill = LGskillData.Skills;
		Baby._AttackSkill = genSkill [(uint)RNGesus.Praise (0, genSkill.Count)];
		Baby._ClassSkill = genSkill [(uint)RNGesus.Praise (0, genSkill.Count)];
		Baby._UtilitySkill = genSkill [(uint)RNGesus.Praise (0, genSkill.Count)];
		Baby._AugmentSkill = genSkill [(uint)RNGesus.Praise (0, genSkill.Count)];


		return Baby;
	}
开发者ID:ryeander,项目名称:LGprototype,代码行数:59,代码来源:LGstatData.cs

示例14: Shuffle_ShouldPreserveOriginalList

        public void Shuffle_ShouldPreserveOriginalList()
        {
            var list = new List<int> {1, 2, 3, 4};
            var expected = new List<int>(list);
            list.Shuffle(RandomProvider.GetRandom(2));

            Assert.Equal(expected, list);
        }
开发者ID:ikhramts,项目名称:NNX,代码行数:8,代码来源:ListExtensionTests.cs

示例15: Shuffle_OrderChanges

 public void Shuffle_OrderChanges()
 {
     // In theory we could get back the exact same order- really unlikely, particularly with larger collections
     int[] source = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
     List<int> items = new List<int>(source);
     items.Shuffle();
     items.Should().NotEqual(source);
 }
开发者ID:Priya91,项目名称:XTask,代码行数:8,代码来源:ListExtensionsTests.cs


注:本文中的List.Shuffle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。