Solved Random Generator

Discussion in 'Plugin Development' started by Lars Mars, Mar 4, 2022.

Thread Status:
Not open for further replies.
  1. Offline

    Lars Mars

    Hey,
    I got a question...
    How can I create a command which gives you a rondom Number and as soon as the Number, for example : "10" comes up, the command is activated?

    I already got a code, but I got a Problem at line 29, cause the Command won't activate, even if the Number equals 10...

    Thanks for the help :D
     

    Attached Files:

  2. Offline

    timtower Administrator Administrator Moderator

    You are making multiple numbers
     
  3. Online

    CraftCreeper6

    @Lars Mars
    Like Tim said, you are making multiple numbers, but you also don't pass anything to randInt in your second call to it, which means it can generate a number from -2147483648 to 2147483647. Your odds of getting a 10 are pretty low ;)

    Equally, Java's randInt function uses an exclusive maximum, so you should pass 11, not 10.
     
  4. Offline

    Lars Mars

    Hey, first of all thanks for your reply. I am new to to the whole coding stuff, so I don't know what I could change. WHat do I need to edit in the code to make it work? I would appreciate an example. Thanks :)
     
    Last edited: Mar 4, 2022
  5. Online

    CraftCreeper6

    @Lars Mars
    It's probably best you try to figure it out for yourself. You are already doing what you need to do on line 28 of your code with the random number, it just needs to be 11 instead of 10 (because it's exclusive). I would recommend you create an integer variable to store the value of the random number, then use that variable to print and compare, this is so that both numbers are the same.
     
  6. Offline

    Lars Mars

    Thank you very much :) Have a nice day
     
  7. Online

    CraftCreeper6

Thread Status:
Not open for further replies.

Share This Page