Jump to content
IGNORED

Do Rand have to start at 0?


WizardBone

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

. . . 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.

 

 

Link to comment
Share on other sites

 

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
 
 
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...