WizardBone Posted November 15, 2016 Share Posted November 15, 2016 Hey guys, I was testing out 'rand' to get a random number. I was reading that it goes from 0 to 255? but how would you set it to be between 30 to 100 as example? cant seem to find out if thats possible, tried somethings nothing really happened. This is example of what I was toying with, excuse the coding, maybe not the best practices. This is for a falling object. y is Y axis and x is X axis. It falls at a rate of 0 to 3 I think. If it hits 98 it will pop back up to 1 and fall again/repeat. When it pops back up the x axis is then also random so it seems to fall in different places. But the problem is it will happen at 0 of the x axis and it looks ugly doing that jumpy flicker teleport thing that happens when you hit the screens edge : ) so yea just trying to adjust the x at will. y= y+(rand&2)+1 if y>98 then y=1 if y=1 then x= (rand&120)+1 Quote Link to comment Share on other sites More sharing options...
bogax Posted November 15, 2016 Share Posted November 15, 2016 (edited) despite of what I said here rand actually ranges 1..255 if you set it to 0 it'll stay 0 (its an LFSR) in that link I describe one way. edit if you use rand16, which I recommend, it can (and I assume, does) return 0 Edited November 15, 2016 by bogax Quote Link to comment Share on other sites More sharing options...
WizardBone Posted November 15, 2016 Author Share Posted November 15, 2016 Well i dont want it to return zero for sure, anywhere from 0 to 30 are numbers I want to avoid. 30 to 120 is what I want. I read what you said in the link, I'll have to re-read a couple times, im not completely sure what its saying yet, but thanks for info! it may be what I need to understand Quote Link to comment Share on other sites More sharing options...
bogax Posted November 15, 2016 Share Posted November 15, 2016 I wrote a short routine to test it and apparently rand16 never returns 0 dim rand16 = aux1 scorecolor = $1E COLUPF = $76 for i = 0 to 255 for j = 0 to 255 if rand = 0 then score = score + 1 if !(j & $3F) then drawscreen next score = score + 1000 next scorecolor = $3A loop drawscreen goto loop Quote Link to comment Share on other sites More sharing options...
bogax Posted November 15, 2016 Share Posted November 15, 2016 (edited) here's a bit of javascript to generate code http://pastebin.com/6PZ2kLtU save it as html and open it in a browser Edited November 15, 2016 by bogax Quote Link to comment Share on other sites More sharing options...
WizardBone Posted November 15, 2016 Author Share Posted November 15, 2016 yeah I dunno, maybe its crappy software im using but every time I save it as html, I just get a page with the script written on it. Weird... Quote Link to comment Share on other sites More sharing options...
bogax Posted November 15, 2016 Share Posted November 15, 2016 yeah I dunno, maybe its crappy software im using but every time I save it as html, I just get a page with the script written on it. Weird... hmm if the download is not working for you you could use the raw button and copy and paste to a text editor and save it as html from there Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted November 15, 2016 Share Posted November 15, 2016 . . . but how would you set it to be between 30 to 100 as example? cant seem to find out if that's possible, tried somethings nothing really happened. The bB page has a chart: randomterrain.com/atari-2600-memories-batari-basic-commands.html#rand Seems like you'd use <variable> = (rand&63) + (rand&7) + 30 Here is a simple example program: test_rand_from_30_to_100_2016y_11m_15d_0021t.bas test_rand_from_30_to_100_2016y_11m_15d_0021t.bin The screen changes color to red when the random number is 30 and green when the random number changes to 100. Quote Link to comment Share on other sites More sharing options...
WizardBone Posted November 15, 2016 Author Share Posted November 15, 2016 (edited) YES thanks man! I can defiantly work with that. I see the numbers in a set range and then the colors change as you say. I haven't tried picking it apart yet but it will for sure help me understand what im doing : ) Edited November 15, 2016 by WizardBone Quote Link to comment Share on other sites More sharing options...
bogax Posted November 18, 2016 Share Posted November 18, 2016 I wrote a short routine to test it and apparently rand16 never returns 0 dim rand16 = aux1 scorecolor = $1E COLUPF = $76 for i = 0 to 255 for j = 0 to 255 if rand = 0 then score = score + 1 if !(j & $3F) then drawscreen next score = score + 1000 next scorecolor = $3A loop drawscreen goto loop Heck! Darn! (other obscenities as required) After actually thinking about it for two seconds it occured to me that, since rand16 goes through every number 1..65535, 0 must come up(since there are certainly combinations of bytes that will produce a 0 when XORed). use rand in an if statement and it just tests the rand variable, it doesn't actually call the rand routine dim rand16 = aux1 scorecolor = $1E COLUPF = $76 for i = 0 to 255 for j = 0 to 255 temp1 = rand if temp1 = 0 then score = score + 1 if !(j & $1F) then drawscreen next score = score + 1000 next scorecolor = $3A loop drawscreen goto loop 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.