Computer Science Canada

[Tutorial][Blitz] Random Numbers

Author:  shorthair [ Mon Feb 16, 2004 10:03 pm ]
Post subject:  [Tutorial][Blitz] Random Numbers

From Blitz Help

Here is a game that lets the user guess on a random number

My First Game
The following program gives the user 5 turns to guess the random number.

; guessing game


While (turnsleft>0)


guess=Input("guess how many sheep I have in my room:")

If guess<sheep Then Print "more than that!"

If guess>sheep Then Print "oh, not that many!

If guess=sheep Then Exit


If turnsleft=0 Then Print "game over dude" Else Print "good guess!"

There are three variables used in this program: turnsleft, sheep and guess.

To begin with, turnsleft is set to 5 and sheep is set to a random number between 0 and 20. The program then enters a "while" loop asking the player to guess a number, and comparing their answer which is placed in the variable guess with the value in sheep.

After playing the game a few times, you may notice that the number of sheep does not vary much. Try adding the following line to the top of the program to "seed" the random number generator using the time of day in milliseconds.

SeedRnd MilliSecs()

Congratulations, you have just doubled the playability of the game with one line of code

Author:  Cervantes [ Tue Feb 17, 2004 5:38 pm ]
Post subject: 

the seed thing.. is that like randomize??

also if you get it on the 5th guess it says gameover dude, but that doesn't matter Smile

Author:  shorthair [ Tue Feb 17, 2004 6:27 pm ]
Post subject: 

because it -1 when you start teh app , so when it gets to that step , you count = 0 even though you got the ans

Author:  Cervantes [ Tue Feb 17, 2004 7:06 pm ]
Post subject: 

yeah I understand why that happens.. Its the seed I don't get. What's this whole thing about the time of day?

Author:  shorthair [ Tue Feb 17, 2004 8:56 pm ]
Post subject: 

well random numbers are not that random , and you can crack the algorithm of the random sequence , to get some really random numbers and make the secuence very very difficult to crak we do a duel randomize by randomizing first like turing does , and then a gain by the milliseconds

Do you understand that ?

Author:  jonos [ Wed Feb 18, 2004 6:37 pm ]
Post subject: 

i don't, could you explain it just alittle more indepth, and is the random Rnd(num), does num = the highest number and 1 = the lowest number

Author:  Cervantes [ Thu Feb 19, 2004 8:27 pm ]
Post subject: 

yeah I think that's what the Rnd(20) means. 20= high 1 = low

I understand the seed time of day thingy now.

For whatever reason jonos Rnd isn't all that random. So shorthair is basically adding whatever number it produces with the number of milliseconds since the day began? or since the program began? either way. And obviously when you add the milliseconds to the rnd it keeps in mind the high and low nums.

Author:  jonos [ Thu Feb 19, 2004 9:25 pm ]
Post subject: 

oh. does anyone know the formula for the "random" numbers.

Author:  shorthair [ Thu Feb 19, 2004 9:28 pm ]
Post subject: 

Dude your talking about mabye a 20 page algorithm , the lkely hood that anyone has craxked it is very very very 0.000000000000001 small., these things are very random , but everything has a system ,you would need to run the random from 1 to 100000000000000000 , just to get a jist of what might be going on

Author:  jonos [ Thu Feb 19, 2004 10:12 pm ]
Post subject: 

yeah, i see what you mean now. someone must have done it though, someone crazy enough.

ive heard of this genius guy who is trying to find the end of pi, and he's been spending his life going through all the numbers of something like that, there must be someone like hta.

Author:  Cervantes [ Fri Feb 20, 2004 6:59 pm ]
Post subject: 

jonos wrote:
trying to find the end of pi

?!?! There is no end to pi!!

Author:  jonos [ Fri Feb 20, 2004 8:28 pm ]
Post subject: 

thats the point kindof.. he just keeps on finding numbers and more numbers.

Author:  edoxus [ Tue Jan 24, 2006 12:20 am ]
Post subject: 

Finding the end pf PI is like finding the end of the universe.

Btw, Idea Idea , got and idea, and you make the user kep pressing keys on the keyboard randomly for 5 sec(like those people that pretend to be typing rlly fast) That would be random enaugh???

nvm, theres a great potential of hacking into it

Author:  edoxus [ Tue Jan 24, 2006 12:26 am ]
Post subject: 

Hmmm... so computer random numbers r not exactly random......
that gives me some Twisted Evil Idea


Next year, im a cisco academe student, that is sure going to improve my hacking skills