Created
April 22, 2016 17:21
-
-
Save kdabir/3a9a187f2d584cbb185f542e88ec1059 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.stream.*; | |
import java.util.function.*; | |
import java.security.SecureRandom; | |
import java.math.BigInteger; | |
class Person { | |
final String name; | |
Person(String name) { this.name = name;} | |
public String toString() { return this.name;} | |
} | |
class RandomPeople { | |
private String generateRandomString(){ | |
return new BigInteger(130, new SecureRandom()).toString(10); | |
} | |
Stream<Person> getPeople() { | |
return Stream.generate(new Supplier<Person>(){ | |
long n = 0; | |
public Person get() { | |
return new Person("person_" + n++ + "-" + generateRandomString()); | |
} | |
}); | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
Stream<Person> stream = new RandomPeople().getPeople(); | |
stream.limit(10).forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment