3 unique random numbers needed. How? More challenging than you would think.

CircleTimeCircleTime Member Posts: 84
edited November -1 in Working with GS (Mac)
Hi Gamesaladers,

Here is a great puzzler for you! Generate 3 unique random numbers from the same set of numbers. Go!
x=rnd(1,25)
y=rnd(1,25)
z=rnd(1,25)
Seems simple so far, but here is the catch... none can be equal to each other!
How, I ask? How dear community, dose one check if it is equal - and then if it is equal, order another random number, then another, then another if need be... until satisfied with a unique one for x,y and z?

Was that too easy?! Then, may I then present the ULTIMATE mind bender for you!
Solve for w! w represents 1 of 10 widgets that we are choosing among. However, each potential widget may be locked or unlocked at any given time, and thus unavailable for selection. Ready... GO!
Let's imagine widgets 3,5,and 8 are locked right now! Generate for w!
w=rnd(1,10)
On no, the selected number 3 is locked. Regenerate! Oh yes, the selected number 5 is unlocked! We are clear and will take 5 for our w. How, my friends? How can you pull off something like THAT in GameSalad???

Do these questions seem too easy? Why am I using forum time for something so basic as random numbers? The reality is my inquiry goes much deeper then generating random numbers. I'm grappling with how logic works in general in Gamesalad. My specific confusion seems to center around how to handle loops. If the random number generated is not available, how do you go back and try again? I have made many, many attempts to model this with attributes. I have an attribute saying if all is good, move onto the next step, next step, next step, however if it is bad go back to an earlier step and regenerate a new random number. This "go back" point is where things break down in Gamesalad. My tests, show Gamesalad dose not do "go back." I think I need a new way to think about approaching this problem. But how? Also, my first 2 questions are real and I need to answer them before my game can move forward.

Optional reading: Background. I'm new here. I've been joyously learning Gamesalad all week. I'm trying to make a trivia game for toddlers. This requires some sort of "logic engine" to select a category, select a question, select alternative wrong answers, etc. I've wanted to engage the forum earlier, but I've been struggling with isolating my specific problems and then articulating my questions.

Thank you in advance,
CircleTime

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    One way would be:

    Generate X first

    Generate Y
    If Y = X, then generate Y again. Otherwise, generate Z.

    Generate Z
    If Z = X OR Z=Y
    Generate Z again.

    That should do it maybe.

    Hope it helps,

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • BarrytheBarrythe Member Posts: 82
    On Tshirtbooths www.gshelper.com there is a video for generating random numbers without repeating. Might not be quite what you're after, and I think QS has basically covered it in the post above anyway but it might help.
  • quantumsheepquantumsheep Member Posts: 8,188
    Oh, don't take my word for it. I make stuff up all the time! :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • calvin9403calvin9403 Member Posts: 3,186
    quantumsheep said:
    Oh, don't take my word for it. I make stuff up all the time! :D

    hah!

    also QS please check your PM

    ___________________________________________________
    http://gshelper.com/
    http://www.gamesaladforum.com/
  • CircleTimeCircleTime Member Posts: 84
    Excellent!
    @quantumsheep I will test this out. Thank you.
    @BarrytheBrave I will watch this now. Thank you.
    I am actively working on this now and will report back with progress. Any additional comments in the meantime are welcome.
    CircleTime
  • quantumsheepquantumsheep Member Posts: 8,188
    Will 'good luck' do?

    QS :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • calvin9403calvin9403 Member Posts: 3,186
    how about "QS"
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi CircleTime; this is surely one of a few GS chestnuts that crops up every now and then! It would be relatively straightforward if there was a "repeat until" behavior; seeing as there isn't, it does get more complicated, as you say.

    I'm certain tshirtbooth's video will do the trick, but here's the way I worked out non-repeating sets of numbers. (I wonder if it's the same way as TSB's?)

    I'll show just non-repeating 2 numbers so you get the gist of it, the Rules for the 3rd number follow the pattern of Rules for the second number with additions of course.

    3 integer atts: x, y and z
    2 integer atts: choice1, choice 2
    boolean attribute: Juggle

    Rule: When touch is pressed/released or when certain att. is true:
    Change att scene.x to rand(1,25)
    Change att scene.y to rand(1,25)

    Rule:
    When All valid:
    att. scene.y = scene.x
    att. scene.x =25
    Change att. scene.y to rand(1,24)

    Rule:
    When All valid:
    att. scene.y = scene.x
    att. scene.x =1
    Change att. scene.y to rand(2,25)

    Rule:
    When All valid:
    att. scene.y = scene.x
    att. scene.x does not equal 1
    att. scene.x does not equal 25
    Change att. scene.y To rand(1,scene.x-1)
    Change att scene.choice1 to scene.y
    Change att scene.y To rand(scene.x+1, 25)
    Change att scene.choice2 to scene.y
    Change att. scene.juggle To rand(0,1)
    rule: when scene.Juggle is false
    Change att. scene.y To scene.choice1
    otherwise
    Change att. scene.y To scene.choice2

    ---then the stuff for third number z (remembering to add: Change att scene.z to rand(1,25) to the very first Rule).

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CircleTimeCircleTime Member Posts: 84
    @gyroscope Thank you for taking the time to write out your solution.

    Current Status: Actively studying / testing TSB's video and gyroscopes solution. Will post more updates as I progress.

    As always, additional comments welcome.

    CircleTime
  • CircleTimeCircleTime Member Posts: 84
    ***Double post*** Not sure if it is allowed. But I've made progress.

    Excellent feedback from everybody. Thank you.
    I am completely enamored by TSB's video solution to use a timer firing off every 0 seconds to basically repeatedly execute and run checks on my random numbers. WOW!!! Love it, and have done some simple things with it thus far...

    Here is the problem, on other posts, there has been plenty of warning about using timers because of a performance ding. How scared should I be? I would like to run a handful of checks with this timer for my trivia type game. I could use this method to prevent picking 2 identical questions in a row, and then to check if any of the 10 potential question categories are locked. I'm about to implement this... Any words of sage advice before I move forth.
  • CircleTimeCircleTime Member Posts: 84
    This timer! Beautiful! Beautiful! Excellent! I just hadn't realized the power of the timer at 0!
    I think all my checks for my trivia generation logic can be handled this way.

    @TSB Cool, now I know how to adjust, only if my frame rate is suffering. Thank you!

    Resolved.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    CircleTime said:

    @TSB Cool...

    Totally agree! One thing though, this is to make sure there's no duplicates one after the other with a single number. Can I ask how you applied this to 3 numbers, different every time, which is what you asked, i.e your x,y and z attributes?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CircleTimeCircleTime Member Posts: 84
    @gyroscope Interesting... maybe I spoke too soon.

    The timer allowed me to answer the part B of my original question - solving for w. Being game specific now, this means I can pick a trivia category 1-10 and not repeat. Also, I can individually check if each category is locked, and reject the locked categories. This is how far I have gotten.

    The next step will be to pick a question in the given category - and then select 2 unique false answers. This is the x, y, z part, the 3 unique numbers. I assumed with the luck I had with timers so far, the good times would just continue to roll.

    I will keep you posted on the progress.

    Current status: studying gyroscope's original solution.

    Any comments as I continue are welcome.
  • RedlerTechRedlerTech Member Posts: 1,583
    I just did this with my memory app! I'd be glad to send it over for free as a template (DO NOT USE MY IDEA) ;)

    Matt :D
    Matthewredler@gmail.com
  • CircleTimeCircleTime Member Posts: 84
    @NextGenEntertainment Thank you! I have sent you a personal email.

    Status update: Struggling. I think gyroscope has pointed me correctly for part A, it just takes me time to fiddle because I am so new to this. Thank you. Any additional feedback appreciated.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi CircleTime; I'm sure Matt's template will do the job well for you; still, I can finish off the Ruling (for attribute z) for you sometime tomorrow, if you like. Always nice to have different ways to accomplish the same thing, I think! :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CircleTimeCircleTime Member Posts: 84
    @ gyroscope Seriously, your assistance is very appreciated. Ultimately I'm going to need to understand and have trivia generation down pat. I'm focusing on edutainment apps, and the cornerstone for all my ideas is a robust and elegant "trivia generation machine" and all the fun/complexities that comes with that. Thanks for your help thus far, and my apologies if I seem slow to digest these new ideas.

    Status update: having fun working with gyroscopes ideas and reviewing NextGenEntertainment's awesome template.
Sign In or Register to comment.