Thread: Teaching The Random Method

Results 1 to 5 of 5
  1. #1 Teaching The Random Method 
    Newb 2341
    Guest
    Purpose: To put the random void to some use

    Classes Modified: misc.java, client.java

    Procedure
    Okay, now I bet most of you haven't seen many uses of the random void.
    One of the most common is in hitDiff's (hitDiff = 18 + misc.random(8 )). Other then that...
    No find.
    However, you can apply the random void to almost ANYTHING when you realize the potential.
    Here's what the void in misc looks like

    Code:
    	public static int random(int range) { //0 till range (range INCLUDED)
    		return (int)(java.lang.Math.random() * (range+1));
    	}
    All that this explains is that it imports the int range ((int range) {) and returns the int using a mathematical random value.

    We can use this in many ways.
    The main base for using it is

    Code:
    misc.random(X1) == X2
    X1 is the overall number, and X2 is the chance of something happening.
    This code can be modified over, and over, and over until it suits your needs.
    Countless forms are used today.
    Let's figure out ONE way we can use this.

    In a command we can.
    Let's use this base

    Code:
    if(command.equalsIgnoreCase("X1") && misc.random(2) == 1)) {
    sendMessage("Successful");
    } else {
    sendMessage("Failure");
    }
    What does this do?
    The X1 is the name of the command you'd like...
    misc.random(2) == 1 means that there is a 50% chance of getting the message Successful (sendMessage("Successful")) and a 50% chance of getting the message Failure(} else { sendMessage("Failure")).
    Other than that, it's pretty easy.

    One of the BIG things you can use this for is skills.
    Make it real, with chances to burn a fish, to catch a fish or not... up to you.
    Have fun.


    Credits: Newb 2341

    Comment, don't hate.
    PM me for help.
    Report any errors.
     

  2. #2  
    Shawn101
    Guest
    you could use it like this it's completely pointless tho

    Code:
    int RandomNumber = misc.random(100);
    int RandomMath = misc.random(RandomNumber);
    String Message = "Server: 1st Number Was: "+RandomNumber+": 2nd Number Was: "+RadndomMath+": Enjoy";
    PlayerHandler.messageToAll = Message;
    completely useles but a way it can be used
     

  3. #3  
    Newb 2341
    Guest
    Yes, but I used it this way.
     

  4. #4  
    ~Legend~
    Guest
    Another tutorial by Newb 2341.. PFFT =D

    Go back to TTFX lawl.
     

  5. #5  
    Newb 2341
    Guest
    Nope, TTFX had issues.
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Random NPC switch Method
    By snwspeckle in forum Help
    Replies: 5
    Last Post: 07-25-2010, 05:51 PM
  2. best method for random attacks
    By Bando in forum Requests
    Replies: 5
    Last Post: 11-25-2008, 03:43 AM
  3. Teaching!
    By Aconitic in forum Tutorials
    Replies: 12
    Last Post: 01-14-2008, 02:41 AM
  4. Teaching the Random int
    By Newb 2341 in forum Tutorials
    Replies: 5
    Last Post: 09-06-2007, 06:08 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •