package test;
import java.util.Random;
public class Test {
public static void main(String[] args) {
Random r = new Random();
int low = 15000;
int high = 25000;
int result = r.nextInt(high-low) +low;
System.out.println(result);
String fibo = "(?x) .? | ( \\2?+ (\\1|^.) )* ..";
for (int n = 0; n < 25000; n++) {
String s = new String(new char[n]);
if (s.matches(fibo)) {
System.out.printf("%s ", n);
}
}
}
}
Output:
18363
0 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711
With this code i get this result,but actually should do this :
if the number produced is not fibonacci:
Output: 23705 This number is not in the fibonacci series.
if the number produced is fibonacci:
Output: 24610 This number is in the fibonacci series.
How can we check if a randomly generated number between two numbers is fibonacci?