Jump to content

I like giving up.

Posted by atari2600land, 28 February 2019 · 138 views

So I searched my blog for LFSR. No results. I guess it's time to give up on the game. I tried the other one, but then the duplicate card checker quit working for no apparent reason. I just wish I was a good programmer. I've done this for years, you'd think I would be great at this. I guess it's just because I'm stupid. Or some people just have a knack of it and I don't.
I did, however, get a fourth item in Yum for Game Boy. It seems like you die faster now that there's 4 things to avoid or get instead of just 3.
And my stupid dad might be coming in to live with us. Just the thought makes me want to vomit in terror. It looks as though he took a cab to the liquor store and got liquor, which isn't allowed at his nursing home, so I think they're kicking him out. I hate alcohol. It's stupid. I want to restart prohibition again. You would, too, if you had to deal with all the crap alcohol has dealt me. I wish you could force people into AA.
So right now I'm pretty angry and upset with the world.

You can always go back to it if you give up.  In time, solution will come to you.

  • Report

But drinking alcohol is the American way. So is smoking.

  • Report

Fortunately, atari2600land has a habit of returning to his abandoned projects. He just needs a nudge over the hill (in this case a random number generator of some sort) and he'll be going again.

  • Report

Hey, programming doesn't come easy to me either.  When I try to help is because I struggled with something for so long that it actually stuck with me, and I can then pass it on. :)


The LFSR (Linear Feedback Shift Register) pseudo-random number generator I posted in C was taken from Wikipedia.  It should work.

#include <stdint.h>
uint32_t lfsr = 1;

/* x^32 = x^15 + x^13 + x^12 + x^9 + x^8 + x^0 */
uint32_t rand(uint32_t bits)
   while (bits-- != 0)
       lfsr = (lfsr >> 1) ^ (lfsr & 1u ? 0x0000B301u : 0);

   return lfsr;

You call that function with the number of bits you want to shift, typically the largest power of 2 that fits the range you wish.  If you are looking for a random number between 0 and 255, then you call it with 8 bits:

   x = rand(8);

That's it.  If it doesn't work, let us know why.


Just to put your mind at ease, I didn't come up with that.  I don't even understand most of the math behind it.  I asked others for help and they helped me arrive at a good implementation and was recommended that something like that would work for my purposes.  I translated that to Intellivision Assembly Language and then was helped a bit more to optimize it.


In the end, it's mostly the work of others, and that's OK.  It is now one more tool in my kit and I don't have to agonize over it ever again.  :)



  • Report