more than one catch on random numbers

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
jetq111
Newbie
Posts: 6
Joined: Sun Oct 15, 2006 7:03 am

more than one catch on random numbers

Post by jetq111 »

hey.
Im making a RPG (my first) where you walk throu a maze and end at one random tile. Dont get it? Example
123456789
1 "#######"
2 "# # # # #"
3 "#--------#"
4 "######"
say you end at row two, but u could exit the maze at either 2,2 2,4 2,6 or 2,8
If i want this to be random (I.E. the computer randomly chooses which of the exits you go to), is their a way to only chose one of those coridantes,
and not one that has a "#" at it? this code wouldnt work:

exitrow: 1
exitcolumn: INT(9*RND)+1
END

this wouldnt work cuz it could chose a number with a # on it. So does anybody know how to make a random number only chose numbers 2, 4, 6, 8
out of my maze?

thnxs

PS srry if this was confusing
PPS the --- in the example are just their so the maze looks right, they wont be their in the end
4815162342
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Re: more than one catch on random numbers

Post by bungytheworm »

jetq111 wrote:So does anybody know how to make a random number only chose numbers 2, 4, 6, 8
out of my maze?
Im not 100% sure are you behind what i think but here is my solution.
It's pure mathematics ;)

Code: Select all

Randomize Timer

For Counter = 1 TO 10
	a = (INT(RND * 4) * 2) + 2 ' 2, 4, 6, 8 are possible values.
	Print a 
	a = 0
Next Counter
Let us know how your project is goin :)
If this was totally wrong answer to your question, sorry. Try explain again.
jetq111
Newbie
Posts: 6
Joined: Sun Oct 15, 2006 7:03 am

Post by jetq111 »

thanks
I was under the impression that if you did somthing like
INT(RND * 30 (.5)) + 1 ' 2 etc would not work.
thanks for the advice.
jetq111

ps
Ill post my game when its done.
thanks
4815162342
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

Glad your problem solved.
Yes, post game here when it's done. New qb games are allways nice to see coming up.
Post Reply