// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { //ElementList and NumberList call their clear method: ElementList.Clear(); NumberList.Clear(); //build method is called: this._build(); //6 random numbers are selected from NumberList, they are added to the ElementList and then removed from NumberList: IEnumerable <int> threeRandom = NumberList.OrderBy(x => Random.Next()).Take(this.ElementNumber); foreach (int y in threeRandom) { ElementList.Add(y); } ElementList.Sort(); NumberList.RemoveAll(c => ElementList.ToList().Exists(n => n == c)); } else { //build method is called: this._build(); //6 random numbers are selected from NumberList, they are added to the ElementList and then removed from NumberList: IEnumerable <int> threeRandom = NumberList.OrderBy(x => Random.Next()).Take(ElementNumber); foreach (int y in threeRandom) { ElementList.Add(y); } NumberList.RemoveAll(c => ElementList.ToList().Exists(n => n == c)); } }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } int IndexToRemove; int NumberToAdd; List <int> RemovedIndexes = new List <int>(); for (int i = 0; i < ElementNumber;) { IndexToRemove = Random.Next(0, SetSize - (1 + RemovedIndexes.Count)); if (RemovedIndexes.IndexOf(IndexToRemove) == -1) { NumberToAdd = NumberList[IndexToRemove]; ElementList.Add(NumberToAdd); NumberList.RemoveAt(IndexToRemove); RemovedIndexes.Add(IndexToRemove); i++; } } ElementList.Sort(); }
public void PickElements() { int randIndex = -1; int uniqueNum = 0; // If ElementList has element(s) then clear both lists and rebuilt if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); // rebuild _numberList data } // Loop trhough number of elements need to add for (int i = 0; i < ElementNumber; i++) { // Generate a random index position between 1 to SetSize (inclusive) randIndex = _Random.Next(1, SetSize); uniqueNum = NumberList.ElementAt(randIndex); // Determine its a duplicate number while (ElementList.Contains(uniqueNum)) { // Then again generate number randIndex = _Random.Next(1, SetSize); uniqueNum = NumberList.ElementAt(randIndex); } // If its a unique number then add to element list ElementList.Add(uniqueNum); } // Sort the ElementList ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- /* * build the _elementList with a set of random numbers. */ public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 0; i < ElementNumber; i++) { int randomPosition = Random.Next(0, NumberList.Count); ElementList.Add(NumberList[randomPosition]); NumberList.RemoveAt(randomPosition); } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); this._build(); } for (int i = 0; i < ElementNumber; i++) { int chance = this.random.Next(0, NumberList.Count); NumberList.Remove(chance); ElementList.Add(chance); } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 1; i <= ElementNumber; i++) { int n = _random.Next(1, 50); NumberList.Remove(n); ElementList.Add(n); } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 1; i <= ElementNumber; i++) { int r = _random.Next(NumberList.Count); ElementList.Add(NumberList[r]); NumberList.RemoveAt(r); } ElementList.Sort(); }
// PUBLIC METHODS +_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+_+ // CREATING the public PickElements method here -------------------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); this._build(); } for (int i = 0; i < ElementNumber; i++) { int Number = aa_random.Next(NumberList.Count); ElementList.Add(NumberList[Number]); NumberList.RemoveAt(Number); } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 0; i < ElementNumber; i++) { int index = random.Next(NumberList.Count); ElementList.Add(NumberList[index]); NumberList.RemoveAt(index); } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 0; i < ElementNumber; i++) { int lottery = _random.Next(NumberList.Count); // element list real number, numberlist = how many list you have ElementList.Add(NumberList[lottery]); // Add NumberList.RemoveAt(lottery); // remove above } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ public void PickElements() { if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } int j = 0; while (j < ElementNumber) { int randPosition = _random.Next(NumberList.Count); ElementList.Add(NumberList[randPosition]); NumberList.Remove(NumberList[randPosition]); j++; } ElementList.Sort(); }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElement() { /* using if statement to clean previously Element list and Number list, then create * new number list so that the newest Element list can be created through for statement */ if (ElementList.Count > 0) { ElementList.Clear(); NumberList.Clear(); _build(); } for (int i = 1; i <= ElementNumber; i++) { //Select random number between 1 to 49 int randomNumber = random.Next(1, 50); //Remove selected number from Number list to avoid selecting repeated number NumberList.Remove(randomNumber); //Add selected number to Element list ElementList.Add(randomNumber); //Sort element list ordered by ascending ElementList.Sort(); } }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { if (ElementList.Count > 0) { // clear if there is elements in ElementList ElementList.Clear(); NumberList.Clear(); // rebuild NumberList _build(); } // create loop to add number to ElementList & remove number from NumberList for (int i = 1; i <= ElementNumber; i++) { int num = random.Next(NumberList.Count); ElementList.Add(NumberList[num]); NumberList.RemoveAt(num); } // sort ascending order small to large ElementList.Sort(); }
//Adds a diagram lines and shapes to an svg document private void AddModelImplementation(Model model) { ElementList list = new ElementList(true); //Add each sorted shape to the svg document foreach (Element element in model.Lines.Values) { if (element.Visible) { list.Add(element); } } //Add each sorted line to the svg document foreach (Element element in model.Shapes.Values) { if (element.Visible) { list.Add(element); } } list.Sort(); //Go through the diagram and add the element by layer; foreach (Layer layer in model.Layers) { if (layer.Visible) { foreach (Element element in list) { if (element.Layer == layer) { AddElement(element); } } } } }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- public void PickElements() { int currentRandom; bool ElementListempty = !ElementList.Any(); bool NumberListempty = !NumberList.Any(); //Checks if both elements assigned with boolean are empty or not if (ElementListempty != true || NumberListempty != true) { //ElementList.Clear() = Empty ElementList.Clear(); NumberList.Clear(); m_build();// will fill the numberList for (int j = 1; j <= ElementNumber; j++) { currentRandom = m_random.Next(1, NumberList.Count); NumberList.Remove(currentRandom); ElementList.Add(currentRandom); } ElementList.Sort();//Sort } }
// PUBLIC METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // CREATE the public PickElements method here ---------------------------- /// <summary> /// pickElements this method generate random numbers. /// after generating remove from numberList and add to elementlist /// </summary> public void PickElements() { int currentRandom; bool ElementListempty = !ElementList.Any(); bool NumberListempty = !NumberList.Any(); //checking if the elementList and NumberList are empty or not if (ElementListempty != true || NumberListempty != true) { //if the lists contain some values the clear is used to make them empty ElementList.Clear(); NumberList.Clear(); m_build();// will fill the numberList for (int j = 1; j <= ElementNumber; j++) { currentRandom = m_random.Next(1, NumberList.Count); NumberList.Remove(currentRandom); ElementList.Add(currentRandom); } ElementList.Sort();//sorting the list } }