#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# A list of numbers with no repeats

Posts: 31Member, PRO
edited April 25

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)

• Posts: 11,269Member, Sous Chef, PRO, Senior Sous-Chef
edited April 25

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

• Posts: 11,269Member, Sous Chef, PRO, Senior Sous-Chef

And if you're anything like me, this thread will blow your mind:

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 31Member, PRO

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.

• Posts: 11,269Member, Sous Chef, PRO, Senior Sous-Chef

@opie2k1 said:
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

• Posts: 11,269Member, Sous Chef, PRO, Senior Sous-Chef
edited April 25

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

• Posts: 31Member, PRO

Wow! Thank you so much for making that for me!

• Posts: 4,585Member, PRO

Text strings are the way to go. Less overhead than tables, faster, better all around.