Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jsyoung43 · Dec 04, 2013 at 09:18 PM · randomstringquizclosed

I am trying to Randomize my Answers?

I am making a multiple choice program that can be edited from a Xml File on completion. I can randomize the answers but can't keep the program from displaying the same answer twice. If someone could point me in the right direction I would be grateful.

Again Thank You for any help

(CONTENT HAS BEEN REMOVED AS OF 15:45 EST 5 DEC 2013)

QUESTION CLOSED THANK YOU

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Dec 04, 2013 at 09:21 PM 0
Share

The most common solution for this kind of problem is to shuffle the answers. That is you would assign your answers in order from the X$$anonymous$$L, then after the array is assigned, a routine would randomly swap answers for some specified number of iterations. $$anonymous$$any post both on UA and on the net cover shuffling.

avatar image Statement · Dec 04, 2013 at 09:29 PM 0
Share

"I can randomize the answers but can't keep the program from displaying the same answer twice." Well, that's the problem with randomness :-)

avatar image ThePunisher · Dec 04, 2013 at 10:22 PM 0
Share

Ohhhh, I see the problem. On level 4 it says "And God said 'Let there be !' and it was EPIC" but Bill $$anonymous$$urray isn't listed as the right answer.

I'm sorry, lol. On a more serious note. I would change the way you're reading the X$$anonymous$$L to use X$$anonymous$$L deserialization which will allow you to retrieve a container with a list all the questions and their choices. Then upon initialization (after deserializing) you can go through each list of choices and just use a simple randomize method.

avatar image alienbaby · Dec 04, 2013 at 10:25 PM 0
Share

^^ That guy gets it.

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by JChilton · Dec 04, 2013 at 10:44 PM

Just shuffle them, then pull one at a time. There's a lotta different ways to do it.

 List<string> answers = new List<string>();
 //add each answer to list
 List<string> shuffledList = new List<string>();
 while(answers.Count > 1){
     int pos = Random.Range(0,answers.Count);
     shuffledList.Add(answers[pos]);
     shuffledList.RemoveAt(pos);
 }
 shuffledList.Add(answers[0]);
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Julien-Lynge · Dec 05, 2013 at 04:14 PM 1
Share

I hope you don't $$anonymous$$d that I converted your comment to an answer. This is exactly it - the definition of pulling in items from a list randomly without duplicating items is to shuffle the list and then simply walk it item by item.

If you want to get fancy and not use an index or removal, you can use a Queue ins$$anonymous$$d of a List.

avatar image Julien-Lynge · Dec 05, 2013 at 04:25 PM 0
Share

Java syntax is nearly identical to C#, so you shouldn't have any problems. Or do you mean Unityscript (which many people call Javascript)?

avatar image Julien-Lynge · Dec 05, 2013 at 04:29 PM 0
Share

Also, I just have to say this:

If you're interning for a company, you are being paid to do this. So you are quite literally asking us to do your work for you, for free.

I'm sure someone here will still help you out, but yeah, it is a bit selfish to ask others to do your job for you, especially since there are so many articles on converting C# to JS and vice versa. Heck, there are even methods that do it for you automatically. For instance: http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/

If you're going to be a professional, getting other people do to your work for you, rather than using an opportunity to learn, isn't going to cut it.

avatar image ThePunisher · Dec 05, 2013 at 06:19 PM 1
Share

Well at that point you'd not only be asking us to help you find the problem, you'd also be asking us to fix it for you, lol.

avatar image sdgd · Dec 05, 2013 at 06:55 PM 0
Share

@ThePunisher is right. +1

@jsyoung43 you should learn how to strip down the program in to simple few lines of code, you'll get better help, better && quicker response, and many of the times you'll figure it your self before asking a question.

else we can see after few years you posting us 5$$anonymous$$ lines of code and asking us to fix your developed problem.

you are the one that knows your program best.

also keep in $$anonymous$$d to mark answers as solved if they helped you. It looks like this is the one that needs to be.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning array element to variable 1 Answer

Trouble displaying lists of strings in a text box 1 Answer

How to check the result after playing in quiz game?[Solve] -1 Answers

How to randomize an array of Strings? 2 Answers

Setting variable to random string from an array? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges