Unity C# Print Strings Randomly From The List After They Get Selected The 2019 Stack Overflow...

What is the closest word meaning "respect for time / mindful"

What do hard-Brexiteers want with respect to the Irish border?

I see my dog run

FPGA - DIY Programming

Shouldn't "much" here be used instead of "more"?

Does the shape of a die affect the probability of a number being rolled?

Geography at the pixel level

How can I autofill dates in Excel excluding Sunday?

Write faster on AT24C32

Is bread bad for ducks?

What tool would a Roman-age civilization have for the breaking of silver and other metals into dust?

Pokemon Turn Based battle (Python)

Are there any other methods to apply to solving simultaneous equations?

Protecting Dualbooting Windows from dangerous code (like rm -rf)

Is "plugging out" electronic devices an American expression?

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

"as much details as you can remember"

What is the meaning of the verb "bear" in this context?

Time travel alters history but people keep saying nothing's changed

Did 3000BC Egyptians use meteoric iron weapons?

Is a "Democratic" Oligarchy-Style System Possible?

Return to UK after being refused entry years previously

How are circuits which use complex ICs normally simulated?

Loose spokes after only a few rides



Unity C# Print Strings Randomly From The List After They Get Selected



The 2019 Stack Overflow Developer Survey Results Are InAdding a duplicate entry randomly into a list in haskell using random monadv2 - Adding a duplicate entry randomly into a list in haskell using random monadWrite a function to extract a given number of randomly selected elements from a listSoftware Key GeneratorConverting from binary to unaryGenerate cryptographically secure random numbers in a specific rangeRepetitive unit tests for a programming languagePermutation of objects, increase maximum limitNode secure randomness implementationsRandomly pick key from dictionary weighted by the keys value





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0












$begingroup$


I have two lists with 4 strings each. I shuffle them and then I select a string on each list to create a combination of strings from both lists. I want the four combinations (written below) repeated four times (so 16 combinations in total) but each of these combination should be presented in a random order.



Dog



Lion



Dog and car



Lion and car



From this code, I shuffle the strings then I select the first string from each list, I iterate using for loops and then generate 16 combinations. This code can shuffle, select and the prints are totally fine BUT prints the first selected string - 4 times, then the second selected string - 4 times. So everything works fine except that the order isn't random. So if dog is selected from the first list, it will print: dog, dog and car, dog, dog and car, then it will do this for lion (for the next 4 prints). So it will always print 4 times the string that gets selected from the first list. Whereas I want those selection to be random. Any advice would be helpful.



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using System;
using System.Linq;

public class randomLetters : MonoBehaviour
{

List<string> mylist = new List<string>();
List<string> mylist2 = new List<string>();


string selected;
string selected2;

void Start()
{
mylist.Add("dog");
mylist.Add("lion");
mylist.Add("dog");
mylist.Add("lion");

mylist2.Add("carfordog");
mylist2.Add("carforlion");
mylist2.Add("carfordog");
mylist2.Add("carforlion");

Shuffle(mylist);
Shuffle(mylist2);

StartCoroutine(Wait());
}


IEnumerator Wait()
{


for (int i = 0; i < 4; i++)
{
selected = mylist[i];

for (int j = 0; j < 4; j++)
{
selected2 = mylist2[j];


if (selected == "dog" && selected2 == "carfordog")
{
Debug.Log("Dog and Car");

}
else if (selected == "dog" && selected2 == "carforlion")
{
Debug.Log("Dog ");
}
else if (selected == "lion" && selected2 == "carforlion")
{
Debug.Log("Lion and Car ");
}
else if (selected == "lion" && selected2 == "carfordog")
{
Debug.Log("Lion");
}

yield return new WaitForSeconds(1);
}

yield return new WaitForSeconds(1);



}

}


void Shuffle(List<string> lists)
{
for (int j = lists.Count - 1; j > 0; j--)
{
int rnd = UnityEngine.Random.Range(0, j + 1);
string temp = lists[j];
lists[j] = lists[rnd];
lists[rnd] = temp;
}
}

}








share







New contributor




FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



















    0












    $begingroup$


    I have two lists with 4 strings each. I shuffle them and then I select a string on each list to create a combination of strings from both lists. I want the four combinations (written below) repeated four times (so 16 combinations in total) but each of these combination should be presented in a random order.



    Dog



    Lion



    Dog and car



    Lion and car



    From this code, I shuffle the strings then I select the first string from each list, I iterate using for loops and then generate 16 combinations. This code can shuffle, select and the prints are totally fine BUT prints the first selected string - 4 times, then the second selected string - 4 times. So everything works fine except that the order isn't random. So if dog is selected from the first list, it will print: dog, dog and car, dog, dog and car, then it will do this for lion (for the next 4 prints). So it will always print 4 times the string that gets selected from the first list. Whereas I want those selection to be random. Any advice would be helpful.



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using TMPro;
    using UnityEngine.UI;
    using System;
    using System.Linq;

    public class randomLetters : MonoBehaviour
    {

    List<string> mylist = new List<string>();
    List<string> mylist2 = new List<string>();


    string selected;
    string selected2;

    void Start()
    {
    mylist.Add("dog");
    mylist.Add("lion");
    mylist.Add("dog");
    mylist.Add("lion");

    mylist2.Add("carfordog");
    mylist2.Add("carforlion");
    mylist2.Add("carfordog");
    mylist2.Add("carforlion");

    Shuffle(mylist);
    Shuffle(mylist2);

    StartCoroutine(Wait());
    }


    IEnumerator Wait()
    {


    for (int i = 0; i < 4; i++)
    {
    selected = mylist[i];

    for (int j = 0; j < 4; j++)
    {
    selected2 = mylist2[j];


    if (selected == "dog" && selected2 == "carfordog")
    {
    Debug.Log("Dog and Car");

    }
    else if (selected == "dog" && selected2 == "carforlion")
    {
    Debug.Log("Dog ");
    }
    else if (selected == "lion" && selected2 == "carforlion")
    {
    Debug.Log("Lion and Car ");
    }
    else if (selected == "lion" && selected2 == "carfordog")
    {
    Debug.Log("Lion");
    }

    yield return new WaitForSeconds(1);
    }

    yield return new WaitForSeconds(1);



    }

    }


    void Shuffle(List<string> lists)
    {
    for (int j = lists.Count - 1; j > 0; j--)
    {
    int rnd = UnityEngine.Random.Range(0, j + 1);
    string temp = lists[j];
    lists[j] = lists[rnd];
    lists[rnd] = temp;
    }
    }

    }








    share







    New contributor




    FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.







    $endgroup$















      0












      0








      0





      $begingroup$


      I have two lists with 4 strings each. I shuffle them and then I select a string on each list to create a combination of strings from both lists. I want the four combinations (written below) repeated four times (so 16 combinations in total) but each of these combination should be presented in a random order.



      Dog



      Lion



      Dog and car



      Lion and car



      From this code, I shuffle the strings then I select the first string from each list, I iterate using for loops and then generate 16 combinations. This code can shuffle, select and the prints are totally fine BUT prints the first selected string - 4 times, then the second selected string - 4 times. So everything works fine except that the order isn't random. So if dog is selected from the first list, it will print: dog, dog and car, dog, dog and car, then it will do this for lion (for the next 4 prints). So it will always print 4 times the string that gets selected from the first list. Whereas I want those selection to be random. Any advice would be helpful.



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using TMPro;
      using UnityEngine.UI;
      using System;
      using System.Linq;

      public class randomLetters : MonoBehaviour
      {

      List<string> mylist = new List<string>();
      List<string> mylist2 = new List<string>();


      string selected;
      string selected2;

      void Start()
      {
      mylist.Add("dog");
      mylist.Add("lion");
      mylist.Add("dog");
      mylist.Add("lion");

      mylist2.Add("carfordog");
      mylist2.Add("carforlion");
      mylist2.Add("carfordog");
      mylist2.Add("carforlion");

      Shuffle(mylist);
      Shuffle(mylist2);

      StartCoroutine(Wait());
      }


      IEnumerator Wait()
      {


      for (int i = 0; i < 4; i++)
      {
      selected = mylist[i];

      for (int j = 0; j < 4; j++)
      {
      selected2 = mylist2[j];


      if (selected == "dog" && selected2 == "carfordog")
      {
      Debug.Log("Dog and Car");

      }
      else if (selected == "dog" && selected2 == "carforlion")
      {
      Debug.Log("Dog ");
      }
      else if (selected == "lion" && selected2 == "carforlion")
      {
      Debug.Log("Lion and Car ");
      }
      else if (selected == "lion" && selected2 == "carfordog")
      {
      Debug.Log("Lion");
      }

      yield return new WaitForSeconds(1);
      }

      yield return new WaitForSeconds(1);



      }

      }


      void Shuffle(List<string> lists)
      {
      for (int j = lists.Count - 1; j > 0; j--)
      {
      int rnd = UnityEngine.Random.Range(0, j + 1);
      string temp = lists[j];
      lists[j] = lists[rnd];
      lists[rnd] = temp;
      }
      }

      }








      share







      New contributor




      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.







      $endgroup$




      I have two lists with 4 strings each. I shuffle them and then I select a string on each list to create a combination of strings from both lists. I want the four combinations (written below) repeated four times (so 16 combinations in total) but each of these combination should be presented in a random order.



      Dog



      Lion



      Dog and car



      Lion and car



      From this code, I shuffle the strings then I select the first string from each list, I iterate using for loops and then generate 16 combinations. This code can shuffle, select and the prints are totally fine BUT prints the first selected string - 4 times, then the second selected string - 4 times. So everything works fine except that the order isn't random. So if dog is selected from the first list, it will print: dog, dog and car, dog, dog and car, then it will do this for lion (for the next 4 prints). So it will always print 4 times the string that gets selected from the first list. Whereas I want those selection to be random. Any advice would be helpful.



      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      using TMPro;
      using UnityEngine.UI;
      using System;
      using System.Linq;

      public class randomLetters : MonoBehaviour
      {

      List<string> mylist = new List<string>();
      List<string> mylist2 = new List<string>();


      string selected;
      string selected2;

      void Start()
      {
      mylist.Add("dog");
      mylist.Add("lion");
      mylist.Add("dog");
      mylist.Add("lion");

      mylist2.Add("carfordog");
      mylist2.Add("carforlion");
      mylist2.Add("carfordog");
      mylist2.Add("carforlion");

      Shuffle(mylist);
      Shuffle(mylist2);

      StartCoroutine(Wait());
      }


      IEnumerator Wait()
      {


      for (int i = 0; i < 4; i++)
      {
      selected = mylist[i];

      for (int j = 0; j < 4; j++)
      {
      selected2 = mylist2[j];


      if (selected == "dog" && selected2 == "carfordog")
      {
      Debug.Log("Dog and Car");

      }
      else if (selected == "dog" && selected2 == "carforlion")
      {
      Debug.Log("Dog ");
      }
      else if (selected == "lion" && selected2 == "carforlion")
      {
      Debug.Log("Lion and Car ");
      }
      else if (selected == "lion" && selected2 == "carfordog")
      {
      Debug.Log("Lion");
      }

      yield return new WaitForSeconds(1);
      }

      yield return new WaitForSeconds(1);



      }

      }


      void Shuffle(List<string> lists)
      {
      for (int j = lists.Count - 1; j > 0; j--)
      {
      int rnd = UnityEngine.Random.Range(0, j + 1);
      string temp = lists[j];
      lists[j] = lists[rnd];
      lists[rnd] = temp;
      }
      }

      }






      c# random unity3d





      share







      New contributor




      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 3 mins ago









      FK22FK22

      1




      1




      New contributor




      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      FK22 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          FK22 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217236%2funity-c-print-strings-randomly-from-the-list-after-they-get-selected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          FK22 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          FK22 is a new contributor. Be nice, and check out our Code of Conduct.













          FK22 is a new contributor. Be nice, and check out our Code of Conduct.












          FK22 is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217236%2funity-c-print-strings-randomly-from-the-list-after-they-get-selected%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          How do i solve the “ No module named 'mlxtend' ” issue on Jupyter?

          Pilgersdorf Inhaltsverzeichnis Geografie | Geschichte | Bevölkerungsentwicklung | Politik | Kultur...