Showing posts with label seed. Show all posts
Showing posts with label seed. Show all posts

Friday, 16 January 2026

Fibonacci-Related Numbers

My diurnal age today is \( \textbf{28047} \) and this number has the interesting property that it's part of a Fibonacci sequence with seed numbers of 3 and 9. This leads to the following sequence of numbers:

3, 9, 12, 21, 33, 54, 87, 141, 228, 369, 597, 966, 1563, 2529, 4092, 6621, 10713, 17334, 28047, ...

These initial numbers form part of OEIS A022379. 

The thought occurred to me that given two seed digits between 0 and 9, there ought to be a limited set of numbers from 10 to let's say 40000 that are generated by two single digit seeds. I got Gemini to write a Python program (permalink) to investigate this and it turns out that there are 651 numbers with this property. Here they are:

10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 120, 121, 123, 124, 125, 126, 128, 129, 131, 133, 134, 136, 137, 138, 139, 141, 142, 144, 146, 147, 149, 150, 152, 154, 155, 157, 159, 160, 162, 163, 165, 167, 168, 170, 173, 175, 176, 178, 180, 181, 183, 186, 188, 189, 191, 194, 196, 199, 201, 202, 204, 207, 209, 212, 215, 217, 220, 222, 223, 225, 228, 230, 233, 236, 238, 241, 243, 246, 249, 251, 254, 257, 259, 262, 264, 267, 270, 272, 275, 280, 283, 285, 288, 291, 293, 296, 301, 304, 306, 309, 314, 317, 322, 325, 327, 330, 335, 338, 343, 348, 351, 356, 359, 361, 364, 369, 372, 377, 382, 385, 390, 393, 398, 403, 406, 411, 416, 419, 424, 427, 432, 437, 440, 445, 453, 458, 461, 466, 471, 474, 479, 487, 492, 495, 500, 508, 513, 521, 526, 529, 534, 542, 547, 555, 563, 568, 576, 581, 584, 589, 597, 602, 610, 618, 623, 631, 636, 644, 652, 657, 665, 673, 678, 686, 691, 699, 707, 712, 720, 733, 741, 746, 754, 762, 767, 775, 788, 796, 801, 809, 822, 830, 843, 851, 856, 864, 877, 885, 898, 911, 919, 932, 940, 945, 953, 966, 974, 987, 1000, 1008, 1021, 1029, 1042, 1055, 1063, 1076, 1089, 1097, 1110, 1118, 1131, 1144, 1152, 1165, 1186, 1199, 1207, 1220, 1233, 1241, 1254, 1275, 1288, 1296, 1309, 1330, 1343, 1364, 1377, 1385, 1398, 1419, 1432, 1453, 1474, 1487, 1508, 1521, 1529, 1542, 1563, 1576, 1597, 1618, 1631, 1652, 1665, 1686, 1707, 1720, 1741, 1762, 1775, 1796, 1809, 1830, 1851, 1864, 1885, 1919, 1940, 1953, 1974, 1995, 2008, 2029, 2063, 2084, 2097, 2118, 2152, 2173, 2207, 2228, 2241, 2262, 2296, 2317, 2351, 2385, 2406, 2440, 2461, 2474, 2495, 2529, 2550, 2584, 2618, 2639, 2673, 2694, 2728, 2762, 2783, 2817, 2851, 2872, 2906, 2927, 2961, 2995, 3016, 3050, 3105, 3139, 3160, 3194, 3228, 3249, 3283, 3338, 3372, 3393, 3427, 3482, 3516, 3571, 3605, 3626, 3660, 3715, 3749, 3804, 3859, 3893, 3948, 3982, 4003, 4037, 4092, 4126, 4181, 4236, 4270, 4325, 4359, 4414, 4469, 4503, 4558, 4613, 4647, 4702, 4736, 4791, 4846, 4880, 4935, 5024, 5079, 5113, 5168, 5223, 5257, 5312, 5401, 5456, 5490, 5545, 5634, 5689, 5778, 5833, 5867, 5922, 6011, 6066, 6155, 6244, 6299, 6388, 6443, 6477, 6532, 6621, 6676, 6765, 6854, 6909, 6998, 7053, 7142, 7231, 7286, 7375, 7464, 7519, 7608, 7663, 7752, 7841, 7896, 7985, 8129, 8218, 8273, 8362, 8451, 8506, 8595, 8739, 8828, 8883, 8972, 9116, 9205, 9349, 9438, 9493, 9582, 9726, 9815, 9959, 10103, 10192, 10336, 10425, 10480, 10569, 10713, 10802, 10946, 11090, 11179, 11323, 11412, 11556, 11700, 11789, 11933, 12077, 12166, 12310, 12399, 12543, 12687, 12776, 12920, 13153, 13297, 13386, 13530, 13674, 13763, 13907, 14140, 14284, 14373, 14517, 14750, 14894, 15127, 15271, 15360, 15504, 15737, 15881, 16114, 16347, 16491, 16724, 16868, 16957, 17101, 17334, 17478, 17711, 17944, 18088, 18321, 18465, 18698, 18931, 19075, 19308, 19541, 19685, 19918, 20062, 20295, 20528, 20672, 20905, 21282, 21515, 21659, 21892, 22125, 22269, 22502, 22879, 23112, 23256, 23489, 23866, 24099, 24476, 24709, 24853, 25086, 25463, 25696, 26073, 26450, 26683, 27060, 27293, 27437, 27670, 28047, 28280, 28657, 29034, 29267, 29644, 29877, 30254, 30631, 30864, 31241, 31618, 31851, 32228, 32461, 32838, 33215, 33448, 33825, 34435, 34812, 35045, 35422, 35799, 36032, 36409, 37019, 37396, 37629, 38006, 38616, 38993, 39603, 39980

The following code (permalink) can be used to find the seeds of any number in this list. It's not impressive code I'm sure but it seems to do the job. Let's try with the last number in the previous list, 39980.

c=39980 L=[] b=round(c/((1+sqrt(5))/2)) L.append(c);L.append(b) a=0 while b>=a and c>b: a=c-b if a <b: c=b b=a L.append(a) L.reverse() if len(str(L[1]))==2: a=L[1]-L[0] b=L[0] print("Seed numbers for Fibonacci sequence are", a,"and",b) X=[a,b] L.remove(L[0]) print(X+L) else: print("Seed numbers for Fibonacci sequence are", L[0],"and",L[1]) print(L)


Seed numbers for Fibonacci sequence are 9 and 4

[9, 4, 13, 17, 30, 47, 77, 124, 201, 325, 526, 851, 1377, 2228, 3605, 5833, 9438, 15271, 24709, 39980]


Interestingly, 39980 is listed in the OEIS as OEIS A022132 but the seeds are listed as 4 and 13 but this is equivalent of course to seeds of 9 and 4. Zero can be a seed number in the first position but it can't then be followed by another zero and so there are 10 x 9 = 90 distinct pairs of single digit seeds. 

Two different pairs of single digit seeds can lead to the same sequence. For example:
  • seeds of 1 and 3 \( \rightarrow\) 1, 3, 4, 7, 11, 18, 29, ...
  • seeds of 2 and 1 \( \rightarrow \) 2, 1, 3, 4, 7, 11, 18, 29, ...
Figure 1 shows a plot of these Fibonacci-related numbers and it's interesting that they form a definite exponential curve with the density of points noticeably thinning out as the numbers become larger.


Figure 1
ADDENDUM:

After completing this post, I discovered that I'd already covered this topic in a post from Thursday, 12th June 2025 titled Fibonacci Numbers Derived From Single Digits. However, in that post I only considered seed digits where the first was smaller than the second and so I discounted a number like 59 because it requires seed digits of 7 and 3 such that the sequence 7, 3, 10, 13, 23, 36, 59 is generated.

Wednesday, 2 July 2025

Building Sequences from a Seed Pair

 FIRST EXAMPLE

The numbers 1 and 4 have the interesting properties that:

  • their sum is prime: 1 + 4 = 5
  • their difference is prime: 4 - 1 = 3
  • their product (4) is the average of a pair of twin primes (3 and 5)
Let's make this the starting point of a sequence and let the third member of the sequence be \(x\). This gives us: \(1, 4, x\). We want 4 and \(x\) to share the properties that 1 and 4 enjoyed. Namely:
  • 4 + \(x\) is prime
  • \(x\) - 4 is prime
  • 4 \(\times x\) is the average of a pair of twin primes
A little trial and error shows that the smallest value of \(x\) we are looking for is 15 because:
  • 4 + 15 = 19 is prime
  • 15 - 4 = 11 is prime
  • 4 \( \times \) 15 = 60 is average of a pair of twin pairs (59 and 61)
By using not trial and error but a simple algorithm we can find further terms. The result is OEIS A154493 and the initial terms are:

1, 4, 15, 28, 39, 50, 81, 350, 459, 512, 675, 944, 987, 1040, 1917, 1936, 2325, 2378, 2421, 2588, 2745, 2812, 3459, 3488, 3495, 3506, 5667, 5804, 6027, 6074, 24765, 24832, 25479, 25552, 27621, 27848, 27951, 27980, 34101, 34720, 34773, 35344

SECOND EXAMPLE

Let's take another seed pair with the simple property that the two numbers must add to a cubic number. We'll use 1 and 7 as our seed pair because: \(1 + 7 = 8 = 2^3\). Here we see that the next number must be 20 because \(7+20=27=3^3\). Using an algorithm, the sequence generated begins thus (permalink):

1, 7, 20, 44, 81, 135, 208, 304, 425, 575, 756, 972, 1225, 1519, 1856, 2240, 2673, 3159, 3700, 4300, 4961, 5687, 6480, 7344, 8281, 9295, 10388, 11564, 12825, 14175, 15616, 17152, 18785, 20519, 22356, 24300, 26353, 28519, 30800, 33200, 35721, 38367

THIRD EXAMPLE

Let's start with seed numbers 1 and 2 this time with the property that:
  • the sum of the two numbers has a digit sum that is prime
  • the product of the two numbers plus 1 has a digit product that is prime
The seed pair 1 and 2 satisfy since:
  • the sum of 1 and 2 is 3 and 3 is prime
  • the product of 1 and 2 plus 1 is 3 and 3 is prime
This leads to the following sequence: 1, 2, 9, 12, 13, 16, 18, 23, 24, 25, 27, 29, 32, 33, 34, 40, 45, 47, 51, 60, 62, 66, 100, ... (permalink). There are 2211 terms in the range up to 40000.

Sunday, 20 January 2019

The Mersenne Twister

I stumbled upon the Mersenne Twister after investigating Pseudorandom Number Generators (PRNGs) stimulated by an article about a hacker who had made a speciality of exploiting weaknesses in the PRNGs incorporated into certain types of slot machines.

Here is an excerpt from the article:
In the course of reverse engineering Novomatic’s software, Alex encountered his first PRNG. He was instantly fascinated by the elegance of this sort of algorithm, which is designed to spew forth an endless series of results that appear impossible to forecast. It does this by taking an initial number, known as a seed, and then mashing it together with various hidden and shifting inputs—the time from a machine’s internal clock, for example. Writing such algorithms requires tremendous mathematical skill, since they’re supposed to produce an output that defies human comprehension; ideally, a PRNG should approximate the utter unpredictability of radioactive decay.
The intriguingly named Mersenne Twister is described thus by Wikipedia:
The Mersenne Twister is a pseudorandom number generator (PRNG). It is by far the most widely used general-purpose PRNG. Its name derives from the fact that its period length is chosen to be a Mersenne prime. 
The Mersenne Twister was developed in 1997 by Makoto Matsumoto and Takuji Nishimura. It was designed specifically to rectify most of the flaws found in older PRNGs. 
The most commonly used version of the Mersenne Twister algorithm is based on the Mersenne prime \(2^{19937}−1\). The standard implementation of that, MT19937, uses a 32-bit word length. 
The Mersenne Twister is the default PRNG for the following software systems: Microsoft Excel, GAUSS,  GLib, GNU Multiple Precision Arithmetic Library, GNU Octave, GNU Scientific Library, gretl, IDL, Julia,  CMU Common Lisp, Embeddable Common Lisp, Steel Bank Common Lisp, Maple, MATLAB, Free Pascal, PHP, Python, R, Ruby, SageMath, Scilab, Stata.
I don't want to delve too deeply into the how the Mersenne Twister actually generates its random numbers. However, the following article provides a simple overview of how it works.

How does the Mersenne Twister work?

Posted February 2016

Someone asked that question on reddit, and so I replied with a high level answer that should provide a clear enough view of the algorithm:

From a high level, here's what a PRNG is supposed to look like (DIAGRAM 1):


DIAGRAM 1

You start with a seed (if you re-use the same seed you will obtain the same random numbers), you initialise it into a state. Then, every time you want to obtain a random number, you transform that state with a one-way function \(g\). This is because you don't want people to find out the state out of the random output.

You want another random number? You first transform the state with a one way function
\(f\): this is because you don't want people who found out the state to be able to retrieve past states (forward secrecy). And then you use your function \(g\) again to output a random number.

Mersenne Twister (MT) is like that, except:
  • your first state is not used to output any random numbers
  • a state allows you to output not only one, but 624 random numbers (although this could be thought as one big random number)
  • the \(g\) function is reversible, it's not a one-way function, so MT it is not a cryptographically secure PRNG.
With more details, here's what MT looks like (DIAGRAM 2):


DIAGRAM 2

The \(f\) function is called "twist", the \(g\) function is called "temper". You can find out how each functions work by looking at the working code on the wikipedia page of MT.

*********************************

The slot machine hacking via knowledge of the PRNG within got me thinking about my own gambling on Lotto, a vice I indulge in weekly. How are the lotto numbers selected? Are there physical, numbered balls involved or is a PRNG used? There's no shortage of sites that will generate random numbers for you to enter in any lottery of your choosing but how are the actual winning numbers generated? Well it seems that the numbers are physically selected in Australian lotteries as shown in the following video:


However, Lucky Lotteries is different.


To quote from the website:
Lucky Lotteries is a raffle style jackpot game that guarantees over 10,000 prizes in every draw! Unlike other lottery games, each number is unique so there is no sharing of prizes. 
There are two Lucky Lotteries games – Super Jackpot and Mega Jackpot. 
Each game has a set amount of numbers per draw and once all available numbers are sold, the winning numbers are drawn using a random number generator.
So clearly a PRNG is used in certain lotteries. Of course, I use SageMath extensively and so it's of interest to know about what PRNG it uses. SageMath documentation explains that:
It is possible to select which random number generator drives the sampling as well as the seed. The default is the Mersenne twister. Also available are the RANDLXS algorithm and the Tausworthe generator (see the gsl reference manual for more details). These are all supposed to be simulation quality generators. For RANDLXS use rng = 'luxury' and for tausworth use rng = 'taus': 
sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)