A92: Re: A85: Random Numbers


[Prev][Next][Index][Thread]

A92: Re: A85: Random Numbers




i don't know how your routine works completely, but i once found a great 
routine to use for randomizing cards in a way that you have great handle 
and speed and still maintain the randomness.  instead of doing this:
1. random
2. check cardlist and grab the random one
3. check if it's in the decklist
4. if so go back to 1, if not then put it in the decklist
5. use the decklist
this routine will slow down the more cards you get rid of.  that means 
at 1 card left it stalls for about 20 seconds (or so).

here's a better routine:
store the cards in a row in a list type format as follows:
$01=ace clubs
$02=ace spades
$03=ace diamonds
...etc.
and place them as:
cards: ds.b 1,2,3,4,5..etc. (excuse my code, i'm not familiar with the 
assembly, i'm just putting something that looks similar to what i mean)
now...have a pointer (let's call it "pt" just for the heck of it) that 
points to the first character in "cards:" and a length (let's call it 
"ln" for the same reason) that starts out as 52 (or however many cards 
you have).  we also need a swap variable, "sw", (unless there's a swap 
command, but i don't know so i'm just using this method), and another 
variable to store the random number into, "rn".

(i'm using english to write the program, so you'll have to translate it 
yourself):
do until ln=1
random between 1 and ln -> rn
ln-1 -> ln
[pt+rn] -> sw  ( the [] i'm using as indirect )
[pt] -> [pt+rn]
sw -> [pt]
pt+1 -> pt
loop
the randomized cards are now in place of "cards:"

in basic you could do the following (ti-85):

 "ASACADAH1S1C..."->a1  (A=ace, S=spades, etc.)
 ""->a4
 lbl over
 lngth a1->a2
 int(a2/2*rand)*2+1->a3
 a2+sub(a1,a3,2)->a4
 sub(a1,1,a3-1)+sub(a1,a3+2,a2-a3-1)->a1
 if lngth a1>2:goto over
 a4+a1->a4

--a4 is the randomized string, if this doesn't work the problem may be 
in the "sub(a1,1,a3-1)+sub(a1,a3+2,a2-a3-1)->a1" line, i don't have a 
working 85 so i'm not sure if you have to check for end of string or 
not, if so then just replace that line with the following:

 if a3+2>a2 then
  sub(a1,1,a3-1)->a1
 else
  sub(a1,1,a3-1)+sub(a1,a3+2,a2-a3-1)->a1
 end

(ti-92 program conversions):
this function returns the exact string you give it except that the first 
character is the randomized card (pulled from the middle of the deck) 
and the cards are shifted right to fill in the spot:

shuffle1(a)    << a=string that is char(1)=ace spades, etc.
 func
  local b
  rand(dim(a))->b
  return mid(a,b,1)&mid(a,1,b-1)&mid(a,b+1)
 endfunc

the following program will shuffle the whole deck (deck is given to the 
program, this allows a range of cards instead of a constant like 52):

shuffle(a)
 func
  local b,c,d
  ""->d
  for b,1,dim(a)-1
   rand(dim(a))->c
   d&mid(a,c,1)->d
   mid(a,1,c-1)&mid(a,c+1)->a
  endfor
  return d&a
 endfunc

-Rob
ICQ:9188921 "No Sol to kill"
e-mail1:rc_ware@hotmail.com
e-mail2:rc_ware@yahoo.com
e-mail3:rc_ware@geocities.com
webpage:http://www.geocities.com/SiliconValley/Haven/4049/index.html

p.s.  just trying to help with randomizing...you can also make it do any 
string, doesn't matter what's in it (cards, codes, etc.), as you can see 
it will just "pull" out a random character.






this does use the refresh register.  when i "shuffled" the cards in
solytare, i did it multiple times though.  i am not sure at how well
it creates random numbers.

-mike

On Wed, 22 Apr 1998 16:26:41 -0500, you wrote:

>
>Hey Mike Pearce,
>
>	What was that random number routine that you got from Mardell's
>ZTetris?  I could sure use it.  I have found out that the random
>numberizer that uses the memory refresh often doesn't give you random
>numbers.  This might be due to a program looping the same commands 
using
>the same memory locations.  Thus the containents of register r aren't
>random.  I don't know, that is my best guess.  Anyway, if you could 
post
>that routine I would really appreciate it.  Thanks.
>							- Mike
>

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com