waderain Posted May 9, 2018 Share Posted May 9, 2018 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? Quote Link to comment Share on other sites More sharing options...
+atari2600land Posted May 9, 2018 Share Posted May 9, 2018 Try using this player1x=(rand/2)+1 : player1y=(rand/4)+1 Although that will give player1x a range of 1-128 and player1y a range of 1-64. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 9, 2018 Share Posted May 9, 2018 Due to how & works you should use values 2^n - 1 such as 127, 63, 31, etc. See Random Numbers for more info, especially the "Did You Know?" on the right. Quote Link to comment Share on other sites More sharing options...
accousticguitar Posted May 9, 2018 Share Posted May 9, 2018 When I was programming Chase It I remember rand16 worked a lot better for me. Quote Link to comment Share on other sites More sharing options...
bogax Posted May 10, 2018 Share Posted May 10, 2018 (edited) Here's one way Here's an explanation of rand & 76 something similar applies to your code. Here's the javascript for generating bB code ranged_rand_generator.html Edited May 10, 2018 by bogax Quote Link to comment Share on other sites More sharing options...
waderain Posted May 10, 2018 Author Share Posted May 10, 2018 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. Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted May 10, 2018 Share Posted May 10, 2018 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. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted May 10, 2018 Share Posted May 10, 2018 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.