mutate Swap Values - Java java.lang

Java examples for java.lang:Math Algorithm

Description

mutate Swap Values

Demo Code


//package com.java2s;

import java.util.Random;

public class Main {
    public static int[][] mutateSwapValues(Random rand, int[][] square,
            int n, int swapCount) {
        int[][] copy = square.clone();

        for (int i = 0; i < swapCount; i++) {
            int r1 = rand.nextInt(n);
            int c1 = rand.nextInt(n);
            int r2 = rand.nextInt(n);
            int c2 = rand.nextInt(n);

            int temp = copy[r1][c1];
            copy[r1][c1] = copy[r2][c2];
            copy[r2][c2] = temp;//  w  ww. jav a2s  .  co m
        }

        return copy;
    }
}

Related Tutorials