package innovimax.mixthem.operation;

import innovimax.mixthem.MixException;
import innovimax.mixthem.arguments.RuleParam;
import innovimax.mixthem.arguments.ParamValue;

import java.util.Arrays;
import java.util.Map;

/**
* <p>Alternate two characters.</p>
* @see ICharOperation
* @author Innovimax
* @version 1.0
*/
public class DefaultCharAlternation extends AbstractCharOperation {
	
	private boolean odd;
	
	/**
	* Constructor
 	* @param params The list of parameters (maybe empty)
	* @see innovimax.mixthem.arguments.RuleParam
	* @see innovimax.mixthem.arguments.ParamValue
	*/
	public DefaultCharAlternation(final Map<RuleParam, ParamValue> params) {
		super(params);
		this.odd = true;
	}
	
	@Override
	public void process(final int c1, final int c2, final CharResult result) throws MixException {
		result.reset();
		final int[] array = new int[1];
		if (c1 == -1) {
			array[0] = c2;
		} else if (c2 == -1) {
			array[0] = c1;
		} else {					
			array[0] = this.odd ? c1 : c2;
			this.odd = !this.odd;			
		}
		result.setResult(Arrays.stream(array));
	}

}

@@ -210,16 +210,41 @@
 til.Map;
+%0Aimport java.util.Random;
 %0A%0A/**%0A* 
@@ -419,42 +419,146 @@
 ate 
-boolean odd;%0A%09%0A%09/**%0A%09* Constructor
+final AltMode mode;%0A%09private boolean odd;%0A%09private final Random random;%0A%09%0A%09/**%0A%09* Constructor%0A%09* @param mode The alternate mode to process
 %0A %09*
@@ -743,16 +743,36 @@
 n(final 
+AltMode mode, final 
 Map%3CRule
@@ -828,18 +828,163 @@
 his.
-odd = true
+mode = mode;%0A%09%09this.odd = true;%0A%09%09this.random = new Random(params.getOrDefault(RuleParam.RANDOM_SEED, AltOperation.DEFAULT_RANDOM_SEED.getValue()).asInt())
 ;%0A%09%7D
@@ -1238,14 +1238,152 @@
 se %7B
-%09%09%09%09%09%0A
+%0A%09%09%09switch (this.mode) %7B%0A%09%09%09%09case RANDOM:%09%09%09%09%09%0A%09%09%09%09%09array%5B0%5D = this.random.nextBoolean() ? c1 : c2;%0A%09%09%09%09%09break;%0A%09%09%09%09case NORMAL:%0A%09%09%09%09default:%0A%09%09
 %09%09%09a
@@ -1412,16 +1412,18 @@
 1 : c2;%0A
+%09%09
 %09%09%09this.
@@ -1438,19 +1438,21 @@
 his.odd;
+%0A
 %09%09%09
+%7D
 %0A%09%09%7D%0A%09%09r

Update DefaultCharAlternation.java