// 1次元ランダムウォーク import java.util.Random; import java.io.*; public class RandomWalk1Dev{ public static void main(String[] args) throws IOException { // int MAX_PARTICLES=10000; double x; double h=1.0; String s; PrintWriter pw = new PrintWriter(new FileWriter("ev.dat")); BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Input: random seed"); s = buf.readLine(); long seed = Long.parseLong(s); System.out.println("Input: Number of steps"); s = buf.readLine(); long nstep = Long.parseLong(s); Random rnd = new Random(); rnd.setSeed(seed); x=0.0; for(int istep=0; istep < nstep; istep++){ double ran=rnd.nextDouble(); if(ran<0.5) x=x-h; else x=x+h; System.out.println(istep+" "+x); pw.println(istep+" "+x); } pw.close(); } }