Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String getRandomMacAddress() {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            builder.append(getRandomMixString(2));
            builder.append(i == 5 ? "" : ":");
        }
        return builder.toString();
    }

    public static String getRandomMixString(int length) {
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int randomInt = (int) (Math.random() * 10);
            if ((randomInt % 2) == 0) {
                char c = (char) (randomInt + 97);
                builder.append(c);
                continue;
            }
            builder.append(String.valueOf(randomInt));
        }

        return builder.toString();

    }
}