Random Spawning

obinna7obinna7 Member, PRO Posts: 4

how can I randomly spawn 7 different numbers that will at any given time add up/subtract to equal an earlier randomly generated 6 digit number

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    That sounds challenging. My question is: how would you do this manually without GameSalad? That is, what is the math you're using to generate seven numbers that add up to a 6-digit number?

    Once I understand that, I can help you figure out how to program that.

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited October 2017

    My first though would be that you could divide 999999 by 7 to get 142857 and 100000 by 7 to get 14286 and then generate seven numbers using random(14286,142857) for each to ensure that the sum of those seven numbers is between 100000 and 999999.

    Once you have the seven numbers (e.g. in a table or as attributes) you could find their sum and you'd have your 6-digit number. If the seven numbers have to be unique, that'd be a bit more trouble to set up but not impossible.

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

  • obinna7obinna7 Member, PRO Posts: 4

    Tatiang thanks for responding.
    The six digit number is first of all randomly generated, that part I can use random(min, max) to get. The part I am I am pondering is how then to randomly generate 7 different numbers that will sum up to the initially generated six digit number. They could be -ve or +ve numbers.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited October 2017

    Well, I just gave you a solution to that. :D

    My advice is not to think of it as taking a six-digit number and then generating seven numbers that add up to it but rather generating seven random numbers and then adding them to create a six-digit number. All of the numbers are random, regardless of what order they are generated. It also doesn't affect which you show to the player first...

    I actually made a quick demo* to test this and it worked great. I didn't add spawning but once the numbers are generated, it's not hard to spawn actors using their values.

    *You'll need the Log Debugger window open to see the results.

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

  • obinna7obinna7 Member, PRO Posts: 4

    Thanks Tatiang,
    Your advice of the way not to think of it also really helps.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You're welcome. I glossed over this the first time I read it:

    They could be -ve or +ve numbers.

    I just realized you meant "negative or positive" numbers. That confuses the method I gave you because if you generate negative and positive numbers at the same time and then add them together, you won't necessarily get a 6-digit number unless you're okay with something like 001568 as a "6-digit number." I'm not really sure how you can force that to happen.

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

Sign In or Register to comment.