![]() |
Forum Index : Microcontroller and PC projects : Help with MMBASIC
Author | Message | ||||
Yourock17 Newbie ![]() Joined: 09/01/2015 Location: AustraliaPosts: 12 |
Hello, I am new to the forum and I have had a little bit of trouble with this fairly simple and annotated program. I have attempted to make a bingo game that announces the numbers on the screen then records them at the bottom of the screen. It is Programed in MMBASIC on the Monochrome Maximite, Firmware is 3.0302. My problem is that (if you have ever played bingo) is that it is putting out the same numbers that it has already put out. I tried to played it with my family, it went for ages. If anyone could give me any ideas that would be nice. 'm is the Maximum Number
't is the Time 'g is the seed 's is the speed 'p is the Pause Length 'a is the final answer 'X is the X axis drawing pos 'Y is the Y axis drawing pos Cls Y = 300 M = 90 1 p = 0 'Resets everything ready for the next num. a = 0 g = 0 t = 0 g = Rnd*m 'Generates A Number If g < 10 Then g = g+20 'Makes it not slow flashing through numbers Do t = t+0.2 a = a+1 'Adds 1 to the scrolling numbers p = g*t 'Make the pause length slower a = a Mod m Pause p Font 3 Print@(190,190) a If a < 10 Then Print@(214,190) "." If p > 400 Then Exit 'If the pause length is 400 Then exit the loop Loop Font 1 Print@(X,Y) a X = X+22 'Starts calculating where to put last bingo num. If X > 460 Then Y = Y+15 X = 0 EndIf Font 2 Print@(135,250,2) "Is The Next Number" Pause 3000 Print@(135,250) " " 'Gets rid of text when going to another num Print@(200,200) " " GoTo 1 Thank you |
||||
halldave![]() Senior Member ![]() Joined: 04/05/2014 Location: AustraliaPosts: 121 |
g = Rnd*m 'Generates A Number Rnd is not a function in mmbasic you need to use rnd() |
||||
ajkw Senior Member ![]() Joined: 29/06/2011 Location: AustraliaPosts: 290 |
You could use an array to track what numbers have already been drawn in a given game. if arrayname(drawnnumber) = 1 then redraw |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6266 |
For this type of game, I prefer to "shuffle the pack" and then deal the cards out from the top, just like normal cards. ' shuffle the pack
' TassyJim Jan 2015 m = 90 ' maximum size of pack dim pack(m) for n = 1 to m ' fill the pack pack(n) = n ' in this case numbers but could be words etc next n for n = m to 1 step -1 ' each pass generates a random number from the REMAINING number of cards k = int(rnd()*n)+1 temp1 = pack(k) ' take a random card from the pack temp2 = pack(n) ' and swap it with the top of the pack pack(n) = temp1 pack(k) = temp2 next n for n = 1 to m print pack(n) next n ' now you can select the numbers in turn for ' as many as required knowing the pack has been shuffled There should be no duplicates and we are not wasting time getting the same number drawn twice. Jim VK7JH MMedit |
||||
Yourock17 Newbie ![]() Joined: 09/01/2015 Location: AustraliaPosts: 12 |
That works as well, But I'm only 15 and started programming a month ago so im fairly new to it all I have little knowledge on arrays. I might look into it Thanks TassyJim for the code but I think I will be good for now. |
||||
ajkw Senior Member ![]() Joined: 29/06/2011 Location: AustraliaPosts: 290 |
Pretty good effort for a first month of programming. I have taken the liberty of changing your code to use a array to check if a random number has been drawn already. Let me know if you would like me to post it. Anthony. |
||||
aargee Senior Member ![]() Joined: 21/08/2008 Location: AustraliaPosts: 255 |
You should have a look at the Randomize command. The random number generator in not truly random (as you are finding). The best thing to do is ask for a number to seed the Randomize command when you start the program and I would then use the last number of your bingo game to then seed the randomize command for the next game. You will then be getting a pseudo random number generated, unless of course you always use the same seed number. Often a real time clock or some other continuously changing value is used as a seed. For crying out loud, all I wanted to do was flash this blasted LED. |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |