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 Paulo33 · Jul 29, 2014 at 02:50 PM · shuffle

Easy way for shuffle a non-repeatable list

After 4 days of research on ways to shuffle lists, seeing old theories like Fisher-Yates and others saw to that Unity is not hard as well.

I simply did a raffle same in real life. In real life a draw is made by a ball full of other small balls with numbers. And the man or woman turns and goes catching small balls one by one, and placing aligned on the table.

Let me give an example, I have 60 small balls inside a cage, I want to give away 6 small balls, then I turn this "cage" to fall 6 small balls with various numbers.

6 These balls were drawn randomly and without order.

In programming is that foundation that I used (C# Example). Using System.Collections.Generic;

 //First create the "cage" with 60 small balls on some void().
     List<int> smallBalls = new List<int>{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60};
     
     //Now i create the "table" for 6 random small balls
     int[] randomBalls = new int[6];
     
     //Now let's try pass the 6 smallBalls to table, look on "for loop i typed 53, because i need 6 balls, so "59 - 6 = 53"
 try{
         for(int i = 0; i <= 53; i++){
             //for catch 6 random number of the "cage" i use Random.Range, and REMOVE    Unsorted numbers...
             smallBalls.RemoveAt(Random.Range(0,smallBalls.Count));
         }
         //Now the "cage" have 6 smallballs with non-repeatable random numbers.
         for(int z = 0; z <= 5; z++){
                 //Geting all smallsballs and passing to int array
             randomBalls[z] = smallBalls[z];
         }
    }
    catch(System.ArgumentOutOfRangeException e){
         return;
    }
 


Now your have the randomBalls Array with 6 non-repeatable random numbers :D This also works for objects, textures, and among others that fit within a list and arrays.

Well it's not literally a question, but if you also have a better example or want to supplement my, please feel free.

Too many people wanting to make drawings of numbers that does not repeat.

Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

23 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 avatar image

Related Questions

Cards: Stacking, drawing, hand, and shuffling 1 Answer

How do I shuffle a list and reset it back to the previous ordering later? 1 Answer

ANSWERED [C#] Coding Noob here- could somebody help with this short shuffling program? 1 Answer

Match 3 Fill Match Gridlock Logic Help 0 Answers

Shuffle Array on button 2 Answers


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