The Student Room Group
Reply 1
Chris_
Can anyone give me advice on how to randomize an array of objects? I want to do this without using a for loop to swop 2 random objects over and over.

Is there any other way to do it?

Thanks.


have you checked

java.util.Randomize.* ?
Reply 2
vienna95
have you checked

java.util.Randomize.* ?


Dont think that exists, does it..?
Reply 3
Chris_
Dont think that exists, does it..?


It isn't in the API docs :/ (unless she meant java.util.random, which does exist).
Reply 4
Nylex
It isn't in the API docs :/ (unless she meant java.util.random, which does exist).


yes, sorry. i meant java.util.random.*

you may have some 3rd party Randomize functions
Reply 5
vienna95
yes, sorry. i meant java.util.random.*

you may have some 3rd party Randomize functions


I dont think there is any, Ive tried searching.

Think Im gonna have to go with the boring 'for' loop, unless anyone can come up with another solution

Thanks for the help anyway.
Reply 6
Chris_
I dont think there is any, Ive tried searching.

Think Im gonna have to go with the boring 'for' loop, unless anyone can come up with another solution

Thanks for the help anyway.


there should be plenty of 3rd party functions...
wait ill find some for you...
*shakes head*
Reply 7
vienna95
there should be plenty of 3rd party functions...
wait ill find some for you...
*shakes head*


Yea, there is plenty of them, just none that I can use for this problem :frown:
Reply 8
Reply 9
vienna95


Ive looked through and cant find anything that addresses the problem directly, but I think there is some useful code in there that I can adapt.

Thanks!
Reply 10
Chris_
Ive looked through and cant find anything that addresses the problem directly, but I think there is some useful code in there that I can adapt.

Thanks!


ye, most are integer array only..
Reply 11
Chris_
Can anyone give me advice on how to randomize an array of objects? I want to do this without using a for loop to swop 2 random objects over and over.

Is there any other way to do it?

Thanks.


I don't think there is a way to do what you require without using some kind of interative functionality (i.e. a for loop, while loop, recursive function etc.). If you find a third-party function which performs what you require, I'd be willing to bet that it also uses some kind of iterative code. There's no built-in ArrayRandomizer package as far as I'm aware... Why are you so adamant about not using a for loop?

Regards,
Reply 12
rahaydenuk
I don't think there is a way to do what you require without using some kind of interative functionality (i.e. a for loop, while loop, recursive function etc.). If you find a third-party function which performs what you require, I'd be willing to bet that it also uses some kind of iterative code. There's no built-in ArrayRandomizer package as far as I'm aware... Why are you so adamant about not using a for loop?

Regards,


Im not overly fussed about using a for loop, and I have no real reason not too (except that everyone will probably use that). I was just looking for something a bit different as a for loop would be nothing new.

What Im trying to do is shuffle a deck of cards, and I thought there might be a direct way of randomizing an array of objects.
Reply 13
rahaydenuk
Why are you so adamant about not using a for loop?



Im just being greedy and trying to get extra bonus marks, is what I should have said :rolleyes: