2 Replies - 753 Views - Last Post: 19 March 2008 - 10:38 PM Rate Topic: -----

#1 Mideval1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

random array

Post icon  Posted 19 March 2008 - 09:41 PM

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){
Is This A Good Question/Topic? 0
  • +

Replies To: random array

#2 Mr. X  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-March 08

Re: random array

Posted 19 March 2008 - 10:33 PM

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

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



Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#3 Mideval1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 04-March 08

Re: random array

Posted 19 March 2008 - 10:38 PM

View PostMr. X, on 19 Mar, 2008 - 10:33 PM, said:

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

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!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1