GameSalad

Random Non-Repeating values based off of user input

Z-BashZ-Bash Posts: 2Member, PRO

I'm trying to make a simple random number generator. I am struggling to randomize numbers without repeating in a sequence. From various tutorials and templates I have been able to do this by manually making tables; however, the problem is when I try to do this based off the user inputted "max" and "min" values.

Ideally I would have the table make a set number of rows based off of the difference between the max and min attributes and fill those rows with consecutive numbers, and after the number is selected it would be removed from the table. Another problem that I may foresee is if the user input a huge number, but I could always limit the maximum value of the "max" attribute.

Thanks for taking the time to read this and I appreciate any help.

Answers

  • tatiangtatiang Posts: 10,916Member, Sous Chef, PRO, Senior Sous-Chef
    edited June 20

    What comes to mind is really messy to set up but you could start with a text string of all possible values:

    x01x02x03x04x05x06x07x08x09x10x11x12

    And then extract a substring when the player chooses a min and max:

    x03x04x05x06x07

    And then choose a random position within that substring and extracting the substring that doesn't contain that value. And then repeating this step.

    How large would the largest number be?

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

  • tatiangtatiang Posts: 10,916Member, Sous Chef, PRO, Senior Sous-Chef

    After I worked out the rules for this (I may still post a demo), I realized that a table is probably still the easiest method. You could just decrease the row range by one each time you delete a row. If you need a demo of that, I can make one.

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

  • tatiangtatiang Posts: 10,916Member, Sous Chef, PRO, Senior Sous-Chef

    Here's my first pass at a table demo. Click the white square to generate non-repeating values within the range (game.min to game.max). Make sure to have the Debugger window open to view the results.

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

  • Z-BashZ-Bash Posts: 2Member, PRO

    Thanks so much! Ideally the number of rows in the table would change based off of what the maximum number is, but I don't think that that is possible with GS. This is the next best thing!

  • tatiangtatiang Posts: 10,916Member, Sous Chef, PRO, Senior Sous-Chef

    That's why I asked how large the largest number would be. If you need the player to pick a number between 1 and 1,000, you'd need a thousand table rows. If you need the player to pick a number between 1 and 1,000,000, you'd need a million table rows. But you would create the table to be that large initially.

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

Sign In or Register to comment.