Turn on thread page Beta
    • Thread Starter
    Offline

    0
    ReputationRep:
    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.
    Offline

    0
    ReputationRep:
    (Original post by 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.* ?
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by vienna95)
    have you checked

    java.util.Randomize.* ?
    Dont think that exists, does it..?
    Offline

    10
    ReputationRep:
    (Original post by Chris_)
    Dont think that exists, does it..?
    It isn't in the API docs :/ (unless she meant java.util.random, which does exist).
    Offline

    0
    ReputationRep:
    (Original post by 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
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by 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.
    Offline

    0
    ReputationRep:
    (Original post by 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*
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by 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
    Offline

    0
    ReputationRep:
    http://www.uni-mannheim.de/fakul/psy...d/PXLabSrc.zip

    find the 'Randomizer.java' file in that zip.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by vienna95)
    http://www.uni-mannheim.de/fakul/psy...d/PXLabSrc.zip

    find the 'Randomizer.java' file in that zip.
    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!
    Offline

    0
    ReputationRep:
    (Original post by 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..
    Offline

    2
    ReputationRep:
    (Original post by 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,
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by 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.
    • Thread Starter
    Offline

    0
    ReputationRep:
    (Original post by 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:
 
 
 
Poll
Is the Big Bang theory correct?
Useful resources

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.