This is a valid RSS feed.
This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
line 304, column 180: (15 occurrences) [help]
... by Terry Brooks - 726 pages </p></description>
^
</channel>
^
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="/css/rss-browser.css" ?>
<rss version="2.0">
<channel>
<title>Perturb.org - Scott's Geek Stuff</title>
<link>http://www.perturb.org/</link>
<description>Just Geek Stuff</description>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1424/</guid>
<title>Vim: Insert a line of characters</title>
<link>http://www.perturb.org/display/entry/1424/</link>
<description><p>I need an 80 character divider of text in Vim. I can never remember the sequence so I'm writing it down:</p>
<pre><code>80i/&lt;ESC&gt;</code></pre>
<p>Will generate:</p>
<pre><code class="language-text">////////////////////////////////////////////////////////////////////////////////</code></pre></description>
<pubDate>Tue, 01 Apr 2025 00:00:00 -0700</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1423/</guid>
<title>Comparing 32bit and 64bit performance on low end micro-controllers</title>
<link>http://www.perturb.org/display/entry/1423/</link>
<description><p>Testing 32bit vs 64bit PRNGs on a 32bit ESP32-C3 <a href="https://gist.github.com/scottchiefbaker/e4c87de8d6c1ad4a33b1ffe5a3ce707f">I'm seeing</a>:</p>
<table>
<thead>
<tr>
<th>PRNG</th>
<th>Iterations per second</th>
<th>Output Bits</th>
<th>Bytes per second</th>
</tr>
</thead>
<tbody>
<tr>
<td>pcg32</td>
<td>487802</td>
<td>32</td>
<td><strong>1951266.7 b/s</strong></td>
</tr>
<tr>
<td>xoroshiro64**</td>
<td><strong>516023</strong></td>
<td>32</td>
<td>2050966.7 b/s</td>
</tr>
<tr>
<td>xoshiro256+</td>
<td>487808</td>
<td>64</td>
<td><strong>3878726.7 b/s</strong></td>
</tr>
<tr>
<td>xoshiro512++</td>
<td>441735</td>
<td>64</td>
<td>3514373.3 b/s</td>
</tr>
<tr>
<td>splitmix64</td>
<td>462290</td>
<td>64</td>
<td>3677033.3 b/s</td>
</tr>
<tr>
<td>pcg64</td>
<td><strong>416297</strong></td>
<td>64</td>
<td>3313060.0 b/s</td>
</tr>
</tbody>
</table>
<p>Very little difference on PRNGs that use 64bit operations vs 32bit operations. Even on limited hardware like this it makes sense to use a 64bit PRNG because you get more bytes per cycle.</p></description>
<pubDate>Wed, 05 Mar 2025 13:47:09 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1422/</guid>
<title>Vim: Convert your syntax highlighted text into HTML</title>
<link>http://www.perturb.org/display/entry/1422/</link>
<description><p>Vim is my code editor of choice as it has great features, excellent syntax highlighting, and a robust plug-in infrastructure. I'm very used to look and feel of Vim. If you want to share some of your code online, converting things to HTML can be problematic. Luckily Vim has a built in code to HTML converter:</p>
<pre><code>:TOhtml</code></pre>
<p>Simply run the <code>:TOhtml</code> command in an open text file and your buffer will be redrawn in HTML which you can then save. Here is a quick sample of my pcg32.pl script <a href="https://www.perturb.org/code/pcg32.pl.html">converted to HTML</a>.</p></description>
<pubDate>Wed, 26 Feb 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1421/</guid>
<title>What kind of number makes a good seed for a PRNG?</title>
<link>http://www.perturb.org/display/entry/1421/</link>
<description><p><a href="https://en.wikipedia.org/wiki/Pseudorandom_number_generator">Pseudo-random number generators</a> use complex math to generate random numbers on your computer. These random numbers are used for all sorts of things: simulations, fractals, games, art, and even math experiments. Computers can <strong>only</strong> do math, which makes generating a random number difficult. </p>
<p>PRNGs need a "seed" number to kick off the math that generates sequences of random numbers. Some PRNGs require a 32bit seed, and some require a 64bit seed. Some PRNGs require one seed, and some require four (or more). It is important to know what type of seed your PRNG needs.</p>
<p>A 32bit number is between 0 and 4.2 billion and a 64bit number is between 0 and 18.4 quintillion. The larger a number is, the more bits are required to store it, and the better a seed it will make. The closer your seed is to the upper end of the number range the better. As a general rule a good seed will be a decimal number with 18 or 19 digits.</p>
<p><code>12</code> is a small number and <strong>not</strong> a good seed, <code>4611686018427387906</code> is a big number but still not a great seed. Seeds should <strong>not</strong> have large sections of zero/one bits. This is why small numbers do not make good seeds. Bits can be visualized by printing the number in binary:</p>
<pre><code class="language-bash"># Horrible
$ perl -E 'printf("%064b\n", 4611686018427387906)'
0100000000000000000000000000000000000000000000000000000000000010
# Bad
$ perl -E 'printf("%064b\n", 17770)'
0000000000000000000000000000000000000000000000000100010101101010
# Poor
$ perl -E 'printf("%064b\n", 2850756010)'
0000000000000000000000000000000010101001111010110001010110101010
# Good
$ perl -E 'printf("%064b\n", 11337502976607798025)'
1001110101010110111001101110001101111000101001000100001100001001</code></pre>
<p>Good seeds should have a <em>roughly</em> even mix of zero and one bits. <code>9223372036854775808</code> is a large number and looks promising but it has 63 zeros, and only a single one bit. You can visualize the quality of your seed with <a href="https://www.perturb.org/code/seed_quality.pl">seed_quality.pl</a>. Quality above 75% should make for good seed numbers.</p>
<p>Seeds should <strong>not</strong> be predictable. Do not use dates, times, or phone numbers as they are potentially guessable. Combinations of numbers can be good sources. Process PID, UID, unixtime are good potential sources <em>if</em> they are combined together in a non-predictable way. PID multiplied by UID multiplied by Unixtime is an example of combining values. Memory locations of variables, especially if <a href="https://en.wikipedia.org/wiki/Address_space_layout_randomization">ASLR</a> is in use is a potentially good source as well.</p>
<p>Hashing numbers, strings, or combinations of numbers can be a good way to generate seeds. Hashing a value with <a href="https://github.com/scottchiefbaker/perl-Crypt-Komihash">Komihash</a> or <a href="https://metacpan.org/pod/Digest::xxHash">xxHash</a> will generate a suitable 64bit number. Hashing a value with <a href="https://metacpan.org/pod/Digest::SHA">SHA256</a> will generate a 256bit value which can be <a href="https://www.perturb.org/display/1415_Perl_Using_sha256_to_hash_strings_into_integers.html">split</a> into four 64bit values. Hashing functions also do a good job of ensuring the bits are mixed well and do not include large repeating sections.</p>
<p>The best source of seed numbers is directly from your OS. On Linux this is <code>/dev/urandom</code> and on Windows you can interface with the <code>RtlGenRandom</code> API. These are carefully curated sources of <em>true</em> randomness, but they can be slow-ish. Using them as a source for a fast PRNG is best practice.</p>
<pre><code class="language-perl">sub get_64bit_seed {
open my $urandom, '&lt;:raw', '/dev/urandom' or croak("Couldn't open /dev/urandom: $!");
sysread($urandom, my $buf, 8) or croak("Couldn't read from csprng: $!");
return unpack("Q*", $buf);
}</code></pre></description>
<pubDate>Thu, 20 Feb 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1420/</guid>
<title>Perl: Multiply-Shift Hash</title>
<link>http://www.perturb.org/display/entry/1420/</link>
<description><p>I've been using the multiply-shift hash lately and have had good results. It's simple, fast, and well tested. </p>
<pre><code class="language-c">// Multiply-Shift Hash
static uint64_t hash_msh(uint64_t x) {
uint64_t prime = 0x9e3779b97f4a7c15; // A large prime constant
x ^= (x &gt;&gt; 30);
x *= prime;
x ^= (x &gt;&gt; 27);
x *= prime;
x ^= (x &gt;&gt; 31);
return x;
}</code></pre>
<p>Whenever I find interesting code like this I like to try and implement it in Perl:</p>
<pre><code class="language-perl">sub hash_msh {
my $x = $_[0];
my $prime = 11400714819323198485;
$x ^= ($x &gt;&gt; 30);
$x = multiply_uv($x, $prime);
$x ^= ($x &gt;&gt; 27);
$x = multiply_uv($x, $prime);
$x ^= ($x &gt;&gt; 31);
return $x;
}
# Perl converts numbers larger than 2^64 - 1 to floating point so
# we 'use integer' to force integer math which retains any overflow.
sub multiply_uv {
my ($one, $two) = @_;
use integer;
my $ret = $one * $two;
no integer;
# Convert signed IV to unsinged UV
if ($ret &lt; 0) {
$ret += 18446744073709551615;
$ret += 1;
}
return $ret;
}</code></pre></description>
<pubDate>Mon, 27 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1419/</guid>
<title>Perl: Calculate number of bits needed to store a number</title>
<link>http://www.perturb.org/display/entry/1419/</link>
<description><p>Quick Perl function to calculate the number of bits required to store a given number.</p>
<pre><code class="language-perl">sub bits_required {
my ($n) = @_;
# Handle special case for 0
return 0 if $n == 0;
# Use logarithm to calculate the number of bits
my $bits = int(log($n) / log(2)) + 1;
return $bits;
}</code></pre></description>
<pubDate>Mon, 27 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1418/</guid>
<title>Implmenting PRNGs in Perl</title>
<link>http://www.perturb.org/display/entry/1418/</link>
<description><p>I'm a big fan of the <a href="https://www.pcg-random.org/download.html">PCG32 PRNG</a>. It's simple, fast, and well documented. As is usually the case when I find interesting code I try and find a way to implement it in Perl. PCG32 poses an interesting problem when one tries to implement it in Perl because all the math is performed using <strong>unsigned</strong> integers and overflow. Most PRNGs use large numbers and overflow to work, that's their secret sauce.</p>
<p>Perl does not have a native unsigned type so I had to learn the guts of how Perl does math so I could emulate it. I ended up coming up with two different implementations, a native Perl implementation, and a version that uses <code>Math::Int64</code>. Surprisingly the native version was <em>significantly</em> faster. </p>
<p>Both implementations with detailed comments are available in <a href="https://www.perturb.org/code/syntax_highlight.php?file=pcg32.pl">pcg32.pl</a> if you're interested in learning more about how to do integer style math in Perl. </p>
<p>As a bonus I also ported the <a href="https://www.perturb.org/code/syntax_highlight.php?file=xoshiro256.pl">xoshiro256 family</a> into Perl. <a href="https://www.perturb.org/code/syntax_highlight.php?file=splitmix64.pl">Splitmix64</a> ended up being a little more complicated to port, but I got it as well.</p></description>
<pubDate>Sat, 25 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1417/</guid>
<title>C/C++: List all #define macros</title>
<link>http://www.perturb.org/display/entry/1417/</link>
<description><p>I need to target a specific platform with some code I'm writing. You can list <strong>all</strong> of the <code>#define</code> macros on a given platform with these commands:</p>
<pre><code>gcc -dM -E - &lt; /dev/null</code></pre>
<pre><code>clang -dM -E - &lt; /dev/null</code></pre>
<p>In this big list of macros you should find something to help you target a given platform.</p></description>
<pubDate>Wed, 22 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1416/</guid>
<title>FFMPEG: Limit the output to only the encoding stats for quieter scripting</title>
<link>http://www.perturb.org/display/entry/1416/</link>
<description><p>FFMPEG is a great tool, but it is very chatty. If you want to encode a file you'll get about 40 lines of headers and track information, most of which you probably will not read. For scripting purposes you probably <strong>only</strong> want to see the statistics. If you start FFMPEG, hide the banner, and set the loglevel low you can output only the stats you need</p>
<pre><code class="language-bash">ffmpeg -y -hide_banner -loglevel quiet -stats ...</code></pre></description>
<pubDate>Tue, 21 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1415/</guid>
<title>Perl: Using sha256 to hash strings into integers</title>
<link>http://www.perturb.org/display/entry/1415/</link>
<description><p>I need 64bit integers to seed some PRNG work I'm doing. I found out that you can easily create four 64bit numbers from any string by using SHA256.</p>
<pre><code>use Digest::SHA;
my $input = $ARGV[0] || int(rand() * 1000000);
# Get raw bytes and convert to an array of uint64_t
my $hash = Digest::SHA::sha256($input);
my @nums = unpack("Q*", $hash);
print "SHA256 Hashing '$input' to: " . join(", ", @nums) . "\n";</code></pre>
<p><strong>Note:</strong> We are using <code>sha256</code> here, not <code>sha256_hex</code> because we need raw bytes to convert to integers with <code>unpack</code>.</p></description>
<pubDate>Mon, 20 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1414/</guid>
<title>Komihash is pretty amazing and simple hashing algorithm</title>
<link>http://www.perturb.org/display/entry/1414/</link>
<description><p>I need a simple way to hash strings into 64bit integers so I started <a href="https://en.wikipedia.org/wiki/List_of_hash_functions#Non-cryptographic_hash_functions">some research</a>. Initially I was focusing on <a href="https://github.com/Cyan4973/xxHash">xxHash</a> but it's slightly harder to implement than other newer hashes. I ended up landing on the amazing <a href="https://github.com/avaneev/komihash">Komihash</a> which bills itself as: "a very fast 64-bit hash function, mainly designed for hash-table, hash-map, and bloom-filter uses".</p>
<p>Komihash is available as a single <code>Komihash.h</code> file and is <em>extremely easy</em> to implement into existing code.</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include "komihash.h"
int main(int argc, char *argv[]) {
int seed = 0;
const char *buf = "Hello world";
uint64_t hash_num = komihash(buf, strlen(buf), seed);
printf("Komihash: %s = %llu\n", buf, hash_num); // 3745467240760726046
}</code></pre>
<p>As a bonus it also comes with a PRNG which is equally simple to implement:</p>
<pre><code class="language-c">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;
#include "komihash.h"
int main(int argc, char *argv[]) {
uint64_t seed1 = time(NULL) * 0x61c8864680b583ebull; // hash64
uint64_t seed2 = seed1 * 0x61c8864680b583ebull; // hash64
for (int i = 0; i &lt; 5; i++) {
uint64_t rand64 = komirand(&amp;seed1, &amp;seed2);
printf("Komirand: %llu\n", rand64);
}
}</code></pre>
<p>In fact, I liked it so much I ported it to Perl and called it <a href="https://github.com/scottchiefbaker/perl-Crypt-Komihash/">Crypt::Komihash</a>.</p></description>
<pubDate>Fri, 17 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1413/</guid>
<title>Perl: Warning about non-portable numbers</title>
<link>http://www.perturb.org/display/entry/1413/</link>
<description><p>If you get a Perl warning about non-portable numbers like this:</p>
<pre><code class="language-bash">Hexadecimal number &gt; 0xffffffff non-portable at /tmp/x.pl line 19.</code></pre>
<p>It means that you are using a hex number greater than 2^32. I dunno why this is a warning when everything is 64bit these days, but it is. There have been a couple of times I needed this in my code so you can disable these warnings with:</p>
<pre><code class="language-perl">no warnings 'portable';</code></pre></description>
<pubDate>Thu, 16 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1412/</guid>
<title>Books of 2025</title>
<link>http://www.perturb.org/display/entry/1412/</link>
<description><p>List of books I read in 2025. Also see the list of <a href="/display/1392_Books_of_2024.html">2024</a>. The date indicated denotes the date I started reading the book. </p>
<p>2025-01-06 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9781250318541">Mistborn</a> by Brandon Sanderson - 643 pages<br />
2025-01-17 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+0812550706">Ender's Game</a> by Orson Scott Card - 324 pages<br />
2025-01-22 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+0451137965">Thinner</a> by Stephen King - 318 pages<br />
2025-01-26 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+0670260770">The Dead Zone</a> by Stephen King - 426 pages<br />
2025-02-02 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9780140074314">The Neverending Story</a> by Michael Ende - 377 pages<br />
2025-02-08 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9781250318572">The Well Of Ascension</a> by Brandon Sanderson - 785 pages<br />
2025-02-21 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9780399130397">Skeleton Crew - The Monkey</a> by Stephen King - 32 pages<br />
2017-02-21 - <a href="//www.google.com/search?tbo=p&amp;q=9780812550757">Speaker for the Dead</a> by Orson Scott Card - 395 Pages<br />
2025-02-27 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+0670855030">Insomnia</a> by Stephen King - 787 pages<br />
2025-03-11 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9781250318626">Hero Of Ages</a> by Brandon Sanderson - 752 pages<br />
2025-03-23 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+0812509250">Xenocide</a> by Orson Scott Card - 592 pages<br />
2025-04-01 - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9781984820709">Tainted Cup</a> by Robert Jackson Bennett - 410 pages </p>
<p>2025-xx-xx - <a href="//www.google.com/search?tbo=p&amp;q=isbn+9780345314253">The Sword Of Shannara</a> by Terry Brooks - 726 pages </p></description>
<pubDate>Wed, 08 Jan 2025 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1411/</guid>
<title>C: Nanoseconds since Unix epoch</title>
<link>http://www.perturb.org/display/entry/1411/</link>
<description><p>I needed a function to use as a simple seed for <code>srand()</code>. Unixtime in nanoseconds changes very frequently and serves as a semi-decent random seed.</p>
<pre><code class="language-c">#include &lt;time.h&gt; // for clock_gettime()
// Nanoseconds since Unix epoch
uint64_t nanos() {
struct timespec ts;
// int8_t ok = clock_gettime(CLOCK_MONOTONIC, &amp;ts); // Uptime
int8_t ok = clock_gettime(CLOCK_REALTIME, &amp;ts); // Since epoch
if (ok != 0) {
return 0; // Return 0 on failure (you can handle this differently)
}
// Calculate nanoseconds
uint64_t ret = (uint64_t)ts.tv_sec * 1000000000ULL + (uint64_t)ts.tv_nsec;
return ret;
}</code></pre>
<p>See also: <a href="/display/1409_Perl_Get_microseconds_since_Unix_epoch.html">Microseconds</a> since epoch in Perl</p></description>
<pubDate>Tue, 31 Dec 2024 00:00:00 -0800</pubDate>
</item>
<item>
<guid isPermaLink="true">http://www.perturb.org/display/entry/1410/</guid>
<title>Git: Show all changes to a given file</title>
<link>http://www.perturb.org/display/entry/1410/</link>
<description><p>If you want to view the history of all the changes you've made to a specific file in Git you can use the <code>log</code> command in Git. This will show you all the commits that touched that file, and the associated commit message. </p>
<pre><code>git log README.md</code></pre>
<p>If you want to see a diff/patch for each commit you can run:</p>
<pre><code>git log --follow --patch README</code></pre>
<p>This can be very useful to track down when a specific piece of code went into (or was taken out of) a file. Be careful as this command only shows you the diff/patch for the file you request. If the commit contains changes to other files you will <strong>not</strong> see those unless you view the full commit.</p></description>
<pubDate>Tue, 31 Dec 2024 00:00:00 -0800</pubDate>
</item>
</channel>
</rss>
If you would like to create a banner that links to this page (i.e. this validation result), do the following:
Download the "valid RSS" banner.
Upload the image to your own server. (This step is important. Please do not link directly to the image on this server.)
Add this HTML to your page (change the image src
attribute if necessary):
If you would like to create a text link instead, here is the URL you can use:
http://www.feedvalidator.org/check.cgi?url=http%3A//www.perturb.org/rss.php