 Author Topic: Programming Corner  (Read 1539 times)

0 Members and 1 Guest are viewing this topic. Digital Walk

• Global Moderator
•     • • Posts: 195
• Karma: 24
• www.kechsoft.co.nr Programming Corner
« on: March 17, 2006, 02:44:48 PM »
This is the place where you can share codes that  can be helpful to all of us.
Plus we can discuss different problems here too www.kechsoft.co.nr Digital Walk

• Global Moderator
•     • • Posts: 195
• Karma: 24
• www.kechsoft.co.nr Programming Corner
« Reply #1 on: March 17, 2006, 04:18:55 PM »
Quote
This is assumed that your familiar with programming and any of the programming languages around.

Language: VB[5,6] , vbscript
Code Complexity: Begginer

For our first post, I will demostrate how to generate random numbers using Rnd and Randomize fiunctions.
Do you remember the Luddo Game? When the dice is rolled, each time we got a new number and some times we got the same number again n again but this Was Rare.

Lets first Dimension /define some variables

DIM DiceNum ' This variable will hold the number generated randomly

DIM MinNum' This will hold the minimum number to begenerated. supose 1

DIM MaxNum' This will hold the maximum number to begenerated.Suppose 6

now we will assign the values to the variables

MinNum=1
MaxNum=6

This is the formula for generating random numbers:
INT(maximum_number - minimum_number + 1) * RND + minimum_number)

Here. if we omit the INT function, the the number returned will be in decimal (e.g 2.5) other wise rounded to the nearest number.
if you dont want to declare the variables of MaxNum and MinNum and put the value directly in to the formula then its ok

RANDOMIZE 'this statement will initialize the random number generator.

DiceNum=INT(maxnum - mininum + 1) * RND+ Min_Num)'any number returned by this formula will be assigned to the DiceNum variable.
For this example we just display the randomly generated number.

MSGBOX DiceNumber.

So how do you like it? Tell me please
Mennat Waar,
JQ[/i][/quote] www.kechsoft.co.nr