Random numbers != to each other

0 favourites
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • I'm trying to make a number generator that will randomize 6 different numbers from 1-100 but i don't want any of those numbers to get duplicated. Getting the random numbers was easy [ (round(random(1,100)) ] is how I made it with the condition Num1 < 1 set Num1 = 1

    Ex: 66, 45, 11,10, 66, 22,

    In this case I would like the two 66 numbers (or 1 of them) to be regenerated to not = 66,45,11,10, or 22.

    Note: Each of the numbers generated are separate global variables as I need each one separate for later use, I don't know if you can accomplish the same task with an array or not, truth be told arrays kinda scare me as i'm not to familiar with them.

  • I suggest using the array instead of global variables.

    Here is how you populate it with unique random numbers:

    (clickable)

  • wow, that is so much more simple then what I have so far. Unfortunately i tried to set it up and just couldn't figure out how you set the "local number R=0" or the X contains value R .... pretty much anything to do with what appears to be an instance var. I look at the snapshot and i don't see any instance var added to the array so i'm stumped.

    Also I forgot to mention that i want to generate a new set of numbers each time i push a button.

  • No, R is not an instance variable. It's a local variable (just select any event and press V to create it).

    Local variables are generally used to temporary store some values while the event is executed.

  • Ohhh ok, well i got the local var set but i'm sure the red X in X contains value R is important and I can't figure that one out either. Which is probably also why i can't figure out how to set Array.CurX to r

    I'm sorry i'm asking all these noob questions but arrays really confuse me even though I understand what there function is setting them up makes my brain bleed.

    Edit: nvm i figured out the Array.CurX to r i was trying to set an instance var again ><

  • The red X means that the event is inverted. Right-click -> Invert.

    In this case it means "if Array NOT contains value r"

    If you want to generate a new set of values when you click a button, I suggest you move this code to a function. And then call this function from "On start of layout" and from "On button clicked".

    https://www.scirra.com/manual/149/function

  • Maybe some snapshots will help, this is my layout, first 6 boxes need the array values in them, the 7th is separate and will have a different value range so it's not really important right now

    This is my current setup and looks just like yours with an extra event for times iv pushed the button and that number will be used as well later

    I'm confident i can figure out the rest after i get past this array roadblock, I just need to get those 6 values into each separate block each time I click and i'm not finding what i'm looking for on the functions page you linked me.

  • how do I up vote you/ increase your rep? I was fiddling around and stumbled upon the solution i was looking for by mistake but it never would have happened without your help. Major props and wish I could give you +++ rep for answering all my nooby questions. Here was the final code for anyone interested

  • I don't know how to increase rep, it seems to be growing by itself

    You should move all actions like "Num1 set text" outside of the loop.

    Click event #1, press B, an empty sub-event will appear at the bottom. Move all those actions to it.

    Also, why are you using TextBox objects? Do you want to allow players to change these values? If not, you need to use Text objects, not TextBox.

  • actually no this isn't going to be a game at all, it's more of a simulation i'm working on to see if i can create a program to predict the outcome of random numbers to a certain degree. Obviously random is random and it can never be perfect but increasing the odds of predicting the most likely of numbers to be generated is the main agenda. This is just the first step in a series of what will likely become very complicated calculations. My biggest problem is knowing how i want to manipulate the numbers but not knowing how to execute it with efficiently through programming.

  • I don't know how to increase rep, it seems to be growing by itself

    I would have done a PM but i don't have the 500 rep required. I have hit another wall and was wandering if you would be interested in helping if your not to busy.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can post your questions here, or if it's a big one - open a new post.

    I would also suggest you study some tutorials <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    https://www.scirra.com/tutorials/all

  • Hey dop2000, your help with my last project has sparked a renewed interest in CS2. I have a TD space shooter project I was working on a long time ago, it's nowhere near finished and the coding i'm sure can be optimized with your help. Most of my inspiration came from a game called Dark Orbit, (now called Dark Orbit reloaded) so you can check that out as well if you wish. I have not purchased the full version of CS2 yet but plan to if you like were this game is headed. I am happy to split any money that can be made from it, i'm more interested in making a game I know I will enjoy and other like me could as well. I'v never tried to make a "sell-able" game before and have always wanted to try. I can send you the game file if you like so you can take a look. Here are a few screen shots of what it looks like so far. I have a ton of really cool ideas for how I want physics objects to react with other objects as well as RPG aspects, crafting, and procedural generation.

    Reply back with any questions you might have about what i'm aiming to create.

  • I like the screenshots, but I can't tell you whether or not you should buy C2, it should be your decision

    And unfortunately, I don't have time for big projects.

    I suggest you post on this forum:

    I still can help with some small coding issues if they arise.

  • Ok, sorry it took so long to reply, iv been supper sick with the flu 103+ temp for almost a week and still trying to get over it. When i'm feeling better ill post some of my code I have so far and see if you want to offer me pointers for optimizing it. I'm also sorry if I came off sounding like I wanted you to make my decision to buy the software, i'v been on the cusp of just doing it anyway cause all the indie games iv come across lately seem like cookie cutters (all the same with no depth). I hesitate a bit to buy CS2 because they now have CS3, anyway you could give me your perspective highlighting the differences between them? If i buy one I want it to cover anything i'm going to need to build my game. Also going to check out that link and if nothing else wanted to thank you a hundred times for all your help.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)