Skip to content

Instantly share code, notes, and snippets.


shelajev/ Secret

Created Nov 13, 2020
What would you like to do?
package primes;
import javax.inject.Singleton;
import java.util.*;
public class PrimesComputer {
private Random r = new Random(41);
public List<Long> random(int upperbound) {
int to = 2 + r.nextInt(upperbound - 2);
int from = 1 + r.nextInt(to - 1);
return primeSequence(from, to);
public static List<Long> primeSequence(long min, long max) {
return LongStream.range(min, max)
public static boolean isPrime(long n) {
return LongStream.rangeClosed(2, (long) Math.sqrt(n))
.allMatch(i -> n % i != 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.