Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tutorial][Blitz] Random Numbers
Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shorthair




PostPosted: 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 guess<sheep Then Print "more than that!"

If guess>sheep 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
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: 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 Smile
shorthair




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




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

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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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, 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
Wink
edoxus




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

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

MUAHAHAHAHHUAHUAH

Next year, im a cisco academe student, that is sure going to improve my hacking skills
MUAHAHAHAHHUAHUAH Twisted Evil
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: