Jump to content
Sign in to follow this  
KevKelley

Randomly Seeding Data Table?

Recommended Posts

I understand the concept of data tables and have had limited use of then but I was wondering if there is a way to randomly seed a data table. 

 

Say I want to randomly generate a series of 12 values to draw 12 different sprites, and then recall them in that order every time needed, or until I reset it, would I simply randomly generate the first number in the data table and then add onto the subsequent values?

 

Share this post


Link to post
Share on other sites

rand is just a counter that counts in a funny sequence

 

if you start from the same spot it will count through the same sequence

Share this post


Link to post
Share on other sites

Data tables normally reside in ROM, so you can't set their values to random values, nor can you change them at runtime. Technically you could have a data table in RAM, but you would have to give up 12 variables to do so, which is probably not what you want.

 

Probably the best way to accomplish what you are wanting is to have a random function of your own that is separate from the built-in bB one, which would require one variable to hold the current seed value. If you set it to a certain seed number, then run the custom rand function 12 times, you will get the same values in the same order every time. If you need them again, then set the seed variable back to the starting value again.  If you need a separate set of 12, pick a different initial seed value, etc.

 

If you want to go this route, I could whip up a sample random function for demonstration purposes.

Share this post


Link to post
Share on other sites

I had just started playing around with an idea. The playfield consisted of 12 boxes. I wanted to flash a sprite in each of the 12 boxes and then disappear. Then one of the 12 sprites would randomly appear and you would have to place that sprite in the correct box. Essentially a game of memory...

 

The only thing I was worried about is that a pattern would develop and it would be easy to guess. 

15904629841858865992023008280384.jpg

  • Like 1

Share this post


Link to post
Share on other sites
8 minutes ago, bogax said:

so you want a shuffle?

 

that's a somewhat different problem (Wikipedia)

 

 

Yeah.  I suppose that would be it.  Once every box would be matched it would then reset, flash the new order of sprites, and then start over.

 

 

Share this post


Link to post
Share on other sites

So maybe a different direction would be assigning each sprite a value. Then a random number outside of the mainloop (r=Rand) and assign each box a value (y=r+1, y=r+2, etc), and then have y point to a data table for what the corresponding sprite would be. Once all boxes are filled then clear the boxes and go back to the random number and start over?

 

Hopefully with enough sprites, positions, and randomizations, it could make a sequence difficult to remember? 

 

I'm just typing out loud playing with this idea to see if it works. Or if this is a rabbit hole I don't really want to go down or not.

Share this post


Link to post
Share on other sites
On 5/25/2020 at 7:24 PM, KevKelley said:

Say I want to randomly generate a series of 12 values to draw 12 different sprites, and then recall them in that order every time needed, or until I reset it, would I simply randomly generate the first number in the data table and then add onto the subsequent values?

 

How would you get 12 sprites?

Share this post


Link to post
Share on other sites

I didn't plan on showing them at the same time. Sorry. I should have clarified.

 

 

 

 

Share this post


Link to post
Share on other sites
Posted (edited)

I'm thinking something like this
this rotates through three for each bit of rand
you could probably find better choices for the three
I tried swapping two but it didn't look very random
(and neither does this really but it looks better than swapping)

I didn't try to analyze it, I just picked some random looking stuff
that is a notoriously bad idea

the details would depend on exactly what you're doing

there's like 500 million permutations of twelve, rand is only 8 bits
and rand16 has a cycle length of 65535

  dim rand16 = z

  rnd = rand
  for i = 0 to 14 step 2
    p = (rnd & 1) | i
    on p goto rr_0 rr_1 rr_2 rr_3 rr_4 rr_5 rr_6 rr_7 rr_8 rr_9 rr10 rr11 rr12 rr13 rr14 rr15
nxt 
    rnd = rnd/2
    next

rr_0  temp1 = sp0 : sp0 =  sp3 :  sp3 = sp10 : sp10 = temp1 : goto nxt
rr_1  temp1 = sp0 : sp0 =  sp6 :  sp6 = sp11 : sp11 = temp1 : goto nxt
rr_2  temp1 = sp1 : sp1 =  sp9 :  sp9 = sp10 : sp10 = temp1 : goto nxt
rr_3  temp1 = sp1 : sp1 =  sp4 :  sp4 = sp11 : sp11 = temp1 : goto nxt
rr_4  temp1 = sp2 : sp2 =  sp7 :  sp7 = sp10 : sp10 = temp1 : goto nxt
rr_5  temp1 = sp2 : sp2 = sp10 : sp10 = sp11 : sp11 = temp1 : goto nxt
rr_6  temp1 = sp3 : sp3 =  sp5 :  sp5 = sp10 : sp10 = temp1 : goto nxt
rr_7  temp1 = sp3 : sp3 =  sp6 :  sp6 = sp11 : sp11 = temp1 : goto nxt
rr_8  temp1 = sp4 : sp4 = sp10 : sp10 = sp10 : sp10 = temp1 : goto nxt
rr_9  temp1 = sp4 : sp4 =  sp6 :  sp6 = sp11 : sp11 = temp1 : goto nxt
rr10  temp1 = sp5 : sp5 =  sp8 :  sp8 = sp10 : sp10 = temp1 : goto nxt
rr11  temp1 = sp5 : sp5 =  sp9 :  sp9 = sp11 : sp11 = temp1 : goto nxt
rr12  temp1 = sp6 : sp6 =  sp8 :  sp8 = sp10 : sp10 = temp1 : goto nxt
rr13  temp1 = sp6 : sp6 =  sp9 :  sp9 = sp11 : sp11 = temp1 : goto nxt
rr14  temp1 = sp7 : sp7 =  sp8 :  sp8 = sp10 : sp10 = temp1 : goto nxt
rr15  temp1 = sp7 : sp7 = sp10 : sp10 = sp11 : sp11 = temp1 : goto nxt
Edited by bogax
typos

Share this post


Link to post
Share on other sites

I never considered that. I have yet to use for and step commands but this could be interesting. Now I am a little confused briefly looking at this.  Would the rr## be the assignment for the sprite location and the sp## the sprite?

 

 

Share this post


Link to post
Share on other sites

yes the rr##'s are the individual rotation routines they just rotate three sprites (you could think of a swap as a rotation of two sprites)

and the sp##'s are the sprites

they're sort of place holders, exactly what they'd end up being would depend on your code

they could be plain bB variables, or you could pack them as nibbles.  or you could make some of them nibbles

and use the sprite x,y for some (assuming the x,y positions would be (different, unique) constants. it would be sort of inside out,

the positions would get shuffled among the sprites instead of the sprites shuffled amongst the positions)

 

Share this post


Link to post
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.

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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...