Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[Tutorial][Blitz] Random Numbers
Author Message
shorthair

Posted: 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.

 code: ; guessing game turnsleft=5 sheep=Rnd(20) While (turnsleft>0) turnsleft=turnsleft-1 guess=Input("guess how many sheep I have in my room:") If guesssheep Then Print "oh, not that many! If guess=sheep Then Exit Wend 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.

 code: SeedRnd MilliSecs()

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

Cervantes

Posted: Tue Feb 17, 2004 5:38 pm   Post subject: (No 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
shorthair

Posted: Tue Feb 17, 2004 6:27 pm   Post subject: (No 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
Cervantes

Posted: Tue Feb 17, 2004 7:06 pm   Post subject: (No subject)

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

Posted: Tue Feb 17, 2004 8:56 pm   Post subject: (No 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 ?
jonos

Posted: Wed Feb 18, 2004 6:37 pm   Post subject: (No 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
Cervantes

Posted: Thu Feb 19, 2004 8:27 pm   Post subject: (No 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.
jonos

Posted: Thu Feb 19, 2004 9:25 pm   Post subject: (No subject)

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

shorthair

Posted: Thu Feb 19, 2004 9:28 pm   Post subject: (No 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
jonos

Posted: Thu Feb 19, 2004 10:12 pm   Post subject: (No 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.
Cervantes

Posted: Fri Feb 20, 2004 6:59 pm   Post subject: (No subject)

jonos wrote:
trying to find the end of pi

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

Posted: Fri Feb 20, 2004 8:28 pm   Post subject: (No subject)

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

Posted: Tue Jan 24, 2006 12:20 am   Post subject: (No subject)

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

Btw, , 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
edoxus

Posted: Tue Jan 24, 2006 12:26 am   Post subject: (No subject)

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

MUAHAHAHAHHUAHUAH

Next year, im a cisco academe student, that is sure going to improve my hacking skills
MUAHAHAHAHHUAHUAH
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 14 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: