[Home]PluggableRobot/Math2

Robo Home | PluggableRobot | Changes | Preferences | AllPages

Showing revision 1
Trying a partial post... hopefully I can put it up in pieces...
/*
 * PluggableRobot, by Robert J. Walker
 * Home page: http://robowiki.net/cgi-bin/robowiki?PluggableRobot
 * This software is made available under the RoboWiki Public Code License (RWPCL). The full text of
 * the license may be found at http://robowiki.net/cgi-bin/robowiki?RWPCL.
 */
package rjw.pluggablerobot;

import java.awt.geom.Point2D;
import java.util.Random;

import robocode.Rules;
import robocode.util.Utils;

/**
 * Math utility class.
 * @author Robert J. Walker
 */
public final class Math2 {
	public static final double PI_OVER_2 = Math.PI / 2;

	private static final Random random = new Random();

	private Math2() {
	}

	/**
	 * Returns a random int between the min and max arguments, inclusive.
	 */
    public static int randomInteger(int min, int max) {
    	return random.nextInt(max - min + 1) + min;
    }

    /**
     * Returns a random double value between 0.0 (inclusive) and 1.0 (exclusive).
     */
    public static double randomDouble() {
    	return random.nextDouble();
    }

    /**
     * If value is less than min, returns min. If value is greater than max, returns max. Otherwise,
     * returns value.
     */
    public static double limit(double min, double value, double max) {
        return Math.max(min, Math.min(value, max));
    }

...

Robo Home | PluggableRobot | Changes | Preferences | AllPages
Edit revision 1 of this page | View other revisions | View current revision
Edited September 22, 2007 4:46 EST by RobertWalker (diff)
Search: