Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Different Random Data Sets

Status
Not open for further replies.

axman505

Technical User
Jun 20, 2001
489
US
I will have an array of items. From this array I will need to obtain two completely different random sets of data. What is the best way to do this?

I can use array_rand to get one set .. but how do i then get a totally different set?

Thanks.
 
but there is no guarentee that will be a completely unique set from the first set. If I needed 2 sets of 500 .. i could just run array_rand(Array, 1000) and split the array in half.

But what if i need a set of 500, and a set of 200 or something like that
 
Select 700 and split it 5/7 to 2/7.

Or treat your arrays like stacks.

Use array_rand() in loops to fetch a single random key each loop iteration. Use that key to push the value to your destination array and remove that value from the original array.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top