Search Java Code Snippets


  Help us in improving the repository. Add new snippets through 'Submit Code Snippet ' link.





#Java - Code Snippets for '#Java.util.Random' - 3 code snippet(s) found

 Sample 1. Generate Random Number till 100

Random rand = new Random();
int randomNumber = rand.nextInt(100);

   Like      Feedback     Random Number Generation  Random


 Sample 2. Code Sample / Example / Snippet of java.util.Random

  public Enumerable<Object[]> scan(DataContext root) {

final Random random = seed >= 0 ? new Random(seed) : new Random();

final Maze maze = new Maze(width, height);

final PrintWriter pw = new PrintWriter(System.out);

maze.layout(random, pw);

if (Maze.DEBUG) {

maze.print(pw, true);

}

return new AbstractEnumerable<Object[]>() {

public Enumerator<Object[]> enumerator() {

final Set<Integer> solutionSet;

if (solution) {

solutionSet = maze.solve(0, 0);

} else {

solutionSet = null;

}

return Linq4j.transform(maze.enumerator(solutionSet),

new Function1<String, Object[]>() {

public Object[] apply(String s) {

return new Object[] {s};

}

});

}

};

}


   Like      Feedback      java.util.Random


 Sample 3. Code Sample / Example / Snippet of java.util.Random

    private File createRandomFileWithContent() throws IOException {

OutputStream fileOut = null;

File file = null;

try {

file = FileUtils.createTempFile(null);

fileOut = new FileOutputStream(file);

byte[] byteArray = new byte[12345];

Random randomContentCreator = new Random();

randomContentCreator.nextBytes(byteArray);

fileOut.write(byteArray);



return file;

}

finally {

try {

if (fileOut != null) {

fileOut.close();

}

}

catch (IOException e) {

throw e;

}

}

}


   Like      Feedback      java.util.Random



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner