Number Sequence Generator
1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39
The number sequence generator produces six kinds of sequence (arithmetic, geometric, Fibonacci, squares, primes and uniform random integers) up to 200 terms, with the defining formula shown above the output. The formula is displayed because a sequence without its rule is just a list of numbers.
How it works
- Arithmetic adds a constant step: a(n) = start + step x n. The step can be negative.
- Geometric multiplies by a constant ratio: a(n) = start x ratio^n. Values grow very quickly.
- Fibonacci adds the two preceding terms, starting 0 and 1.
- Squares gives (start + n)^2 for successive n.
- Primes lists integers greater than 1 divisible only by 1 and themselves, found by trial division up to the square root.
- Random draws uniform integers between two bounds, and is the only kind that repeats values.
JavaScript numbers are IEEE 754 doubles, so integers stay exact only up to 2^53. Geometric sequences and Fibonacci pass that point quickly, Fibonacci at term 79, and a geometric sequence with ratio 2 at term 53.
Examples
An arithmetic sequence
Sequence
Arithmetic
Start
1
Step
2
Terms
10
Result
1, 3, 5, 7, 9, 11, 13, 15, 17, 19
a(n) = 1 + 2n for n from 0 to 9. The odd numbers. A negative step counts down instead.
Fibonacci past the safe integer limit
Sequence
Fibonacci
Terms
80
Result
Correct to term 78; from term 79 onwards the values lose precision
Fibonacci term 79 is 14,472,334,024,676,221, which exceeds 2^53. Beyond that point the displayed values are approximations, not exact integers.
Frequently asked questions
Why do large sequence values become inaccurate?
Because JavaScript represents all numbers as IEEE 754 doubles, which hold integers exactly only up to 2^53, about 9 quadrillion. Fibonacci crosses that at term 79 and a doubling geometric sequence at term 53. Past that the values are the nearest representable double, not the true integer.
How are the prime numbers found?
By trial division: each candidate is tested against divisors up to its square root. That is slower than a sieve for large ranges but simpler and entirely fast enough for the 200-term maximum here.
Can the step or start value be negative?
Yes for arithmetic and geometric sequences. A negative step counts down, and a negative geometric ratio alternates sign on each term. Fibonacci, squares and primes take no parameters.
Does the random option repeat values?
Yes, and unlike the other options it should. Uniform random draws from a range are independent, so duplicates are expected, a 20-term sequence from 1 to 10 will certainly repeat.