Jump to content
  • 0

Best Way For Randomly Split


Question

Posted (edited)

Hello guys!

 

Im trying to find the best way to split 3 Vectors...

 

example:

public static Vector<L2PcInstance> players = new Vector<>();

Contains 50 players.

 

I want to split them to 25 - 25 but not taking 1 by 1 .. i want randomly selection in the next 2 vectors

public static Vector<L2PcInstance> vec1 = new Vector<>();
public static Vector<L2PcInstance> vec2 = new Vector<>();

Im always missing something and the result isnt correct. Someone can help me? 

Thank you!!!

Edited by melron

Recommended Posts

  • 0
Posted

Alright then im doing it wrong... And im asking again now, Even if i will use a list to store them ....

Then i have to do the same thing to suffle them right?.......... :D

 

Forget about vectors.. lets say i have list ... i want just the way for a random split for 2 other lists...

You can use the 

Collections.shuffle(list)

to suffle the list.

After you add the elements onto the list use it to suffle it.

  • 0
Posted

Hello guys!

 

Im trying to find the best way to split 3 Vectors...

 

example:

public static Vector<L2PcInstance> players = new Vector<>();

Contains 50 players.

 

I want to split them to 25 - 25 in the next 2 vectors

public static Vector<L2PcInstance> vec1 = new Vector<>();
public static Vector<L2PcInstance> vec2 = new Vector<>();

Im always missing something and the result isnt correct. Someone can help me? 

Thank you!!!

show code

  • 0
Posted (edited)

show code

What code do you need? i havent ready code that working thats why im asking for help...

 

players = 50 players

 

vec1 = 0

vec2 = 0;

 

how i can randomly split the players to vec1 & vec2.

 

Sorry for no posting my code but i think its rly useless since im looking the way for a split

Correct me if im wrong

 

Edit: Actually i havent something to show you.. i just want to create this code 

Edited by melron
  • 0
Posted (edited)

Bla bla bla, you afraid of people leeching your code? If i don't see the code you ain't take your answer.

 

Byeee  :-[

Yea u found it! 

as im saying....

Edit: Actually i havent something to show you.. i just want to create this code

 

i havent ready code to show you im just want find this way to split...

To explain it again:

 

players using the command .example

When the list 'players' collect 50 people the registration will close.

 

after that i want to split the players in these 2 vectors randomly so i can continue work with them...

i think you can understand what i mean.. i wanna start making something...

 

atm the code is here but as i said isnt showing something... You dont need these..

 

Open registrations

 

 

protected void openRegistrations()
   {  
       state = State.REGISTER;
       Broadcast.announceToOnlinePlayers(".::Event::.");
       Broadcast.announceToOnlinePlayers("In one minute registration will be close!");
       ThreadPoolManager.getInstance().scheduleGeneral(new checkRegist(), 60000 );
   } 

 

 

check registrations

Event.java

 

 

protected void Registrations()
    {
	   try
	   {
	       state=State.LOADING;
	       
	       if(players.isEmpty() || players.size() < 50)
	       {
	           Broadcast.announceToOnlinePlayers("Event aborted due to innactivity!");
	           clean();
	           return;
	       }
	       Broadcast.announceToOnlinePlayers("In 30 seconds players will shuffle");
	       ThreadPoolManager.getInstance().scheduleGeneral(new shuffle, 30000 ); 
	   }
	   catch (Exception e)
	   {
		   _log.warning("Error event" + e.getMessage());
	   }
	   
    } 

 

 

 

Say2.java

 

 

checkCommand(_text,activeChar);
		       if(_text.equalsIgnoreCase(".example") || _text.equalsIgnoreCase(".example"))
		           return;

 

 

 

checkCommand in Say2.java

 

 

static void checkCommand(String text,L2PcInstance player)
	   {
	       if(text.equalsIgnoreCase(".example"))
	       {
	           if(Event.players.contains(player))
	           {
	               player.sendMessage("You have already registed to the event.");
	               return;
	           }
	           if(Event.state == Event.State.INACTIVE)
	               return;
	           if(Event.state != Event.State.REGISTER)
	           {
	               player.sendMessage("Event has already started.");
	               return;
	           }
	           Event.players.add(player);
	           player.sendMessage("You registed to the event!!");
	           return;
	       }

 

 

 

And in shuffle i want to make this split... So??

Edited by melron
  • 0
Posted (edited)

Why the fuck you use vector ?

i updated my previous post you can take a look

Edited by melron
  • 0
Posted (edited)

I don't know why you want use vector. Probably you want create 3 teams which is bad lel. You need create teamHolders no vectors but even if you want create vectors i won't go against it.

 

Make a for to all elements of players and use a variable i and check if i > 15 to add the player into vector 1 (then do i++) else add player into vector 2

if this is what you want.

for (int i=0; i <= players.size();)
{
   if (i<=15)
      vectorplayers1.add(players.get(i));
   else
      vectorplayers2.add(players.get(i));
   i++;
}

something like this maybe? i don't even know vector i dont use it.

 

Just giving you the idea on how to split into 3 vectors

Edited by AccessDenied
  • 0
Posted (edited)

I don't know why you want use vector. Probably you want create 3 teams which is bad lel. You need create teamHolders no vectors but even if you want create vectors i won't go against it.

 

Make a for to all elements of players and use a variable i and check if i > 15 to add the player into vector 1 (then do i++) else add player into vector 2

if this is what you want.

for (int i=0; i <= players.size();)
{
   if (i<=15)
      vectorplayers1.add(players.get(i));
   else if (i>15 && i<=30)
      vectorplayers2.add(players.get(i));
   else
      vectorplayers3.add(players.get(i));
   i++;
}

something like this maybe? i don't even know vector i dont use it.

 

Just giving you the idea on how to split into 3 vectors

Thank you for your help, I want 2 teams (the players vector will be clean after the split)

im trying to use a kind of shuffle ... with your way its like the first 25 players go to team1 and the others go to team 2.. i want random selection :/

 

p.s if i can do this one with a better way i will not say no :D

 

But if i will use a list or something , I  should do the same method as im searching now... Am i wrong?

Edited by melron
  • 0
Posted

Thank you for your help, I want 2 teams (the players vector will be clean after the split)

im trying to use a kind of suffle ... with your way its like the first 25 players go to team1 and the others go to team 2.. i want random selection :/

 

p.s if i can do this one with a better way i will not say no :D

 

But if i will use a list or something , I  should do the same method as im searching now... Am i wrong?

 

Making teams don't even use vectors or arrays lel 

what if u need 5 teams u will make 5 vectors? you use sets stored into 1 array.

  • 0
Posted (edited)

Making teams don't even use vectors or arrays lel 

what if u need 5 teams u will make 5 vectors? you use sets stored into 1 array.

Alright then im doing it wrong... And im asking again now, Even if i will use a list to store them ....

Then i have to do the same thing to shuffle them right?.......... :D

 

Forget about vectors.. lets say i have list ... i want just the way for a random split for 2 other lists...

Edited by melron
  • 0
Posted

You can use the 

Collections.shuffle(list)

to suffle the list.

After you add the elements onto the list use it to suffle it.

Thank you!

Guest
This topic is now closed to further replies.
×
×
  • Create New...