Random generator - urgent

Hi,

In matlab, there is this random generator  that is called rand "that returns a pseudorandom, scalar value drawn from a uniform distribution on the unit interval."

Lets say I need to find the equilavent in java, is nextFloat, nextDouble or the Random generator itself.

Math.random()

Pls help.thanks
Jasbir21Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
java.util.Random should be OK

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jim CakalicSenior Developer/ArchitectCommented:
Math.random constructs an instance of Random to use for servicing getDouble calls. So Math.random and Random.getDouble are equivalent. If this is insufficient for your needs, you might have a look at the random package of Colt: http://dsd.lbl.gov/~hoschek/colt/

Regards,
Jim Cakalic
borislavmarkovCommented:
import java.util.Random;

public class Dummy {
    public static void main(String[] args)
    {
        double rangeMin = 5;
        double rangeMax = 10;
        Random r = new Random(System.currentTimeMillis());
        System.out.println("INT:"    + ((int)rangeMin + r.nextInt((int)rangeMax-(int)rangeMin)));
        System.out.println("FLOAT:"  + (rangeMin + r.nextFloat()*(rangeMax-rangeMin)));
        System.out.println("DOUBLE:" + (rangeMin + r.nextDouble()*(rangeMax-rangeMin)));

    }
}
Jasbir21Author Commented:
Thanks a lot
CEHJCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.