A list of numbers with no repeats
opie2k1
Member, PRO Posts: 36
I'm trying to create a list of 10 random numbers with no repeats at all but I can't seem to wrap my head around it. For example, the first time I run the program I might get:
1,2,3,4,5,6,7,8,9,0
and the next time
3,2,7,5,9,0,8,1,4,6
Ideally, I'd like to save each value in a cell in a table. Any help would be AWESOME!
Thanks!
(I've seen lots of posts on how to make sure there are no immediate repeats but I can't seem to find a post/video that has this situation)
Comments
Create a table with each value in a separate row. When choosing a number, do this:
Change attribute self.row to random(1,tableRowCount(tableName)
Change attribute self.number to tableCellValue(tableName, self.row, 1)
Delete Table Row at index self.row
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
And if you're anything like me, this thread will blow your mind:
http://forums.gamesalad.com/discussion/68841/random-numbers-no-repeating
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thanks for the response! I saw the "deleting table row" method after I posted this but I was hoping for a more elegant solution. I did actually find that thread you mentioned and it's an AWESOME formula but unfortunately it seems to just not repeat the last number as opposed to what I want which is to not repeat any numbers.
Oh sorry, I think you're right. I haven't used that formula myself so I had forgotten it was an elegant solution to a different problem.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
You can do the same thing with a text string. Let me see if I can make a quick demo...
Click to select and display a random number.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Wow! Thank you so much for making that for me!
Text strings are the way to go. Less overhead than tables, faster, better all around.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support