Jump to content
IGNORED

random number question/problem


waderain

Recommended Posts

I've sort of noticed using RAND to generate random numbers isn't really randomizing numbers or maybe I'm doing something wrong. I've been putting together a game and I want player1 to appear randomly around the screen after it had been shot..

 

sort of like this

 

player1x = (rand&120)+1:player1y = (rand&50)+1

 

But I noticed a pattern would develop and it will only place the sprite in certain locations of the screen, mainly the upper left or the lower right. Never in the middle or other corners.

 

In programming in Visual Basic I know if I want true random numbers I need to put a RANDOMIZE function somewhere in the declaring section. Is there something similar in Batari Basic or am I missing something?

Link to comment
Share on other sites

Yeah, I've tried several different rand variations. Some are better than others but you can see a pattern develop over time. I even tried one of my old Basic random number tricks and it still comes back with a pattern. I get the feeling it resets itself after it loops.

Link to comment
Share on other sites

Yeah, I've tried several different rand variations. Some are better than others but you can see a pattern develop over time. I even tried one of my old Basic random number tricks and it still comes back with a pattern. I get the feeling it resets itself after it loops.

 

Like SpiceWare pointed out, I got rid of the patterns by using rand16 and mixing division and AND:

 

Even when using rand16, it seems that using only division or only AND (&) from the chart below can create visible patterns sometimes. If you notice a pattern when using AND, mixing in a little division should get rid of the patterns.

Link to comment
Share on other sites

Yeah, I've tried several different rand variations. Some are better than others but you can see a pattern develop over time. I even tried one of my old Basic random number tricks and it still comes back with a pattern. I get the feeling it resets itself after it loops.

The numbers are not truly random, the sequence will repeat after 255 values. I go into detail here.

 

One thing that helps is to grab a rand number every single frame and ignore it. What that does is make the human a factor, if it takes a fraction of a second longer to hit RESET than before then the numbers actually used by your game will be different.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...