Welcome to Dream.In.Code
Become a Java Expert!

Join 150,418 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,065 people online right now. Registration is fast and FREE... Join Now!




random array

 
Reply to this topicStart new topic

random array

Mideval1
19 Mar, 2008 - 08:41 PM
Post #1

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 5


My Contributions
I'm trying to populate a random array with the min value of 1 and a max value of 10000. I want to use the Math.random method to generate random numbers to fill the array. I have the following but am somewhat stumped as to how to continue. Any help would be greatly appreciated.

public void populateRandomArray(int [] randomArray, int minValue,
int MaxValue){

User is offlineProfile CardPM
+Quote Post

Mr. X
RE: Random Array
19 Mar, 2008 - 09:33 PM
Post #2

New D.I.C Head
Group Icon

Joined: 19 Mar, 2008
Posts: 7


Dream Kudos: 50
My Contributions
Hello there. Is this something like what you were wanting?

CODE

for (i = 0; i < randomArray.length; i++)
{
    randomArray[i] = (int) Math.floor(maxValue + Math.random() * (minValue - maxValue + 1));
}


Hope that helps.
User is offlineProfile CardPM
+Quote Post

Mideval1
RE: Random Array
19 Mar, 2008 - 09:38 PM
Post #3

New D.I.C Head
*

Joined: 4 Mar, 2008
Posts: 5


My Contributions
QUOTE(Mr. X @ 19 Mar, 2008 - 10:33 PM) *

Hello there. Is this something like what you were wanting?

CODE

for (i = 0; i < randomArray.length; i++)
{
    randomArray[i] = (int) Math.floor(maxValue + Math.random() * (minValue - maxValue + 1));
}


Hope that helps.



This helps a lot!! Thank You!
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:17PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month