java.security.SecureRandom()で乱数を生成するサンプル

サンプルコード

package com.arkgame.study;

import java.security.SecureRandom;

public class SecureRandDemo {

	public static void main(String[] args) {
		SecureRandom rand = new SecureRandom();
		String cftLst = "abcdefghijklmnopqrstuvwxyz0123456789";
		String target = "";
		for (int i = 0; i < 8; i++) {
			int cft = rand.nextInt(cftLst.length());
			target += cftLst.charAt(cft);
		}
		System.out.println("結果:" + target);
	}

}

結果:8gbq8noa

Java

Posted by arkgame