katalyst Posted February 3, 2010 Posted February 3, 2010 Alright i'm having a little problem at the moment. Long story short i need to switch the numbers in 2 places of arrays. Here's a little sample of something sort of like i want. for(int i=0;i<10;i++){ array[i]=array[random.nextInt(10)]; } What that little chunk there does is randomly set the number to another number in that arrays place. I can't figure out how to make the random array slot that is chosen equal to the one that i'm using the loop for. I hope i'm making sense. Pretty much with what i have there i get multiples of the array slots. Ex. array[]={10,20,30,40,50,60,70,80,90,100}; I get: array[0]=10; array[1]=30; array[2]=10; array[3]=50; array[4]=60; array[5]=20; array[6]=10; array[7]=40; array[8]=100; array[9]=70; I want: array[0]=20; array[1]=50; array[2]=70; array[3]=80; array[4]=10; array[5]=30; array[6]=60; array[7]=40; array[8]=100; array[9]=90; see how it doesn't repeat Well i want that. Anyone want to give me a basic less then 5 line loop that will do that for me?
Noah Posted February 4, 2010 Posted February 4, 2010 idk much java but the parameter for nextInt might be whats causing 10 to repeat try putting i, or just nothing... if that doesnt work idk what to tell ya for(int i=0;i<10;i++){ array[i]=array[random.nextInt(10)]; }
Hex` Posted February 4, 2010 Posted February 4, 2010 I'm sorry but i don't know what to do in that situation, but i bet that this topic is getting spammed by +1'ers soon.
Jim Posted February 5, 2010 Posted February 5, 2010 I don't know. Big Jim is always glad to be of assistance.
katalyst Posted February 5, 2010 Author Posted February 5, 2010 I don't know. Big Jim is always glad to be of assistance. : ) well next time idk what's going on I think i'll have to ask you. Java can be such a pain in the ass sometimes. Python is nicee and easy. Just make a set and fill it. Can't duplicate a number in a set so your gravy.
Bows 0n Fire Posted February 5, 2010 Posted February 5, 2010 Go oldschool and program in C. Shit's so cash.
Recommended Posts