Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Making a Random Number Generator for Blackjack

Author
Message
nick newbie
18
Years of Service
User Offline
Joined: 17th Feb 2006
Location:
Posted: 19th Feb 2006 03:17
Hey guys in order to verify my understanding of the BASIC Language and prepare myself to make a text based adventure game I'm trying to port an old game of Blackjack from Java to DBPro. So far things have gone fairly well but I'm having problems generating a different set of random numbers that I need to make the game.

A friend suggested that I seed the random number generator based the systems time. But, the get time command returns the systems time as a string rather then an integer which is what I need. Based on preliminary research in dbpro, I've been unable to find a command that will convert a string to an integer so that approach just might be out.

To simplify my problem I'll just state it quite simply. How do I create the base for a random number generator that will give me a different set of random numbers each time my program is run?

If it helps I'll post the original Java source code as well as DBPro code that I'm working on now. Sorry for the messiness of the Java code btw I had to write it on a Unix machine several years ago.

Thanks in Advance

</Nicolas>

Attachments

Login to view attachments
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 19th Feb 2006 11:03 Edited at: 19th Feb 2006 11:12
randomize(timer())

timer() returns the amount of time in milliseconds since the system booted and wraps around every three moths or so, just randomize by that value, also.

Quote: "I've been unable to find a command that will convert a string to an integer "


check out VAL in the help or the manual



Windows: 32 bit extension/graphical shell for a 16bit patch to an 8bit OS originally coded for a 4bit CPU, written by a 2bit company that can't stand 1bit of competition, now available in 64bits.
The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 20th Feb 2006 04:26
weird, I have always just done randomizetimer()
nick newbie
18
Years of Service
User Offline
Joined: 17th Feb 2006
Location:
Posted: 20th Feb 2006 17:33
Great thanks for the help guys. Now that I've seeded it that way and I know it works how do I tell the computer to pick a random number from 1 to 12 based on that seed?

Thanks again

</Nicolas>
Chilled Programmer 420
18
Years of Service
User Offline
Joined: 24th Nov 2005
Location: NOT SAYING!, i dont wanna get kidnapped!
Posted: 21st Feb 2006 21:56 Edited at: 21st Feb 2006 21:56
randomize timer()
number=rnd(11)+1

the rnd(11) will select: 0,1,2,3,4,5,6,7,8,9,10,11 the plus 1 will
make it into a 1-12

[url=www.freewebs.com/tyhrfg][img]bruce.bmp[/img][/url]
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 22nd Feb 2006 10:45
I didn`t notice how I forced that operation until it was commented upon, just as an explanation, I always specificaly force the operator precedence with brackets (as in "randomize (timer())") because I play about with a lot of different languages, the one thing they have in common is that they often use slightly different operator precedence (some even have no precedence), even amongst other BASIC languages, so I am in the habit of ensuring operations proceed in the order I intended by forcing it with parenthesis, I do this with every operation, it gets to be second nature to think of the sequence and stick in the brackets, more typing, but it saves problems in some cases, as Chillaxed and Digital Dude say, the brackets are not strictly needed.



Windows: 32 bit extension/graphical shell for a 16bit patch to an 8bit OS originally coded for a 4bit CPU, written by a 2bit company that can't stand 1bit of competition, now available in 64bits.
Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 22nd Feb 2006 22:36
you aint seen anything yet then (I allow my readers to exhale/inhale at the commas btw)




Windows: 32 bit extension/graphical shell for a 16bit patch to an 8bit OS originally coded for a 4bit CPU, written by a 2bit company that can't stand 1bit of competition, now available in 64bits.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 23rd Feb 2006 17:24
give this a look
http://www.thegamecreators.com/?m=codebase_view&i=3ad5fdf422f8760be4d724be871866f4

its a code base entry i posted a while ago.

heres the description:
Quote: "Summary
Loads any number of Decks of Standard Playing Cards into a UDT Array from external files.

Full Description
This code needs only the included source file, and 4 external text files to run. The code shows how to use data stored in external files to build a deck, or multiple decks of standard playing cards, which are then held in a User Defined Type Array. Nothing is hard-coded in that changing the value in decks.txt will correctly build the Cards UDT Array. This code uses pure DBP Code for all of the logic and functionality. The included main source file makes use of my DBP_NETLIB Plugin's Variable Watcher feature for data viewing purposes only - It is NOT necessary that you have this plugin and any references to it can be remmed out in your main code. If you decide to use the DBP_NETLIB plugin it can be found at www.mod2software.com/dbp/dbp.htm (Please view the documents before using the DBP_NETLIB Plugin) The UDT in this code can easily be extended to include any set of elements you like which lends itself well to any type of 2D or 3D card game. Use a recursive random number generator and the Cards UDT Array IsUsed property to always draw unique/unsused cards from your created Deck(s).

The attached code module (Include) can be dropped into any project as is. Your main code need only call the InitCardLoader() function to fully populate and build the deck(s) of cards."


FREE Automatic file updates for your distributed Games and Apps - see Program Announcements Forum - DBP Demo

Login to post a reply

Server time is: 2024-09-24 17:37:11
Your offset time is: 2024-09-24 17:37:11