mutate Swap Values In Place - Java java.lang

Java examples for java.lang:Math Algorithm

Description

mutate Swap Values In Place

Demo Code


//package com.java2s;

import java.util.Random;

public class Main {
    public static void mutateSwapValuesInPlace(Random rand, int[][] square,
            int n, int swapCount) {
        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 = square[r1][c1];
            square[r1][c1] = square[r2][c2];
            square[r2][c2] = temp;/*from   w  w w . j a  v a  2 s.c  o  m*/
        }
    }
}

Related Tutorials