Wrox Programmer Forums
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 6th, 2005, 09:09 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default random

I have a random integer added to a variable that should, well, be random every time it is ran. But, for some reason, it shows the same random number every time I try the script.
The script is at http://24.106.93.59/game1.asp

This is what I have for the random part:


Sub Fight

intPlayAttack = intPlaySTR - Cint(intMonstDEF/2)
intMonstAttack = intMonstSTR - Cint(intPlayDEF/2)
intPlayAttackD = (intPlayAttack + int(rnd*3))
intMonstAttackD = (intMonstAttack + int(rnd*3))

intPlayChanceAttack = Cint(intPlayDEX/intMonstDEF * 100)
intMonstChanceAttack = Cint(intMonstDEX/intPlayDEF * 100)
intPlayCAR = int(rnd*100)
intMonstCAR = int(rnd*100)

If intPlayChanceAttack > intPlayCAR Then
intPlayAttack = intPlayAttackD
Else
intPlayAttack = intPlayAttack
End If
If intMonstChanceAttack > intMonstCAR Then
intMonstAttack = intMonstAttackD
Else
intMonstAttack = intMonstAttack
End If

If intPlayAttack < 0 Then
intPlayAttack = 0
End If
If intMonstAttack < 0 Then
intMonstAttack = 0
End If

intMonstHPAF = intMonstHPAF - intPlayAttack
intPlayHPAF = intPlayHPAF - intMonstAttack

Response.Write "You have attacked for: <b>" & intPlayAttackD & "</b><br>"
Response.Write "You have been attacked for: <b>" & intMonstAttackD & "</b><br>"
Response.Write "You have: <b>" & intPlayHPAF & "</b> health remaining. <br><br>"

If intPlayHPAF <= 0 Then
Call Death
End If
If intMonstHPAF <= 0 Then
Call Victory
End If
If intPlayHPAF > 0 and intMonstHPAF > 0 Then
Call Fight
End If
End Sub



I just started leaning ASP, and thought making a game would be a good little project just to see what I can do. If you can help me, it would be great. Also, if you need the entire code here, I'll post that.
 
Old January 6th, 2005, 10:37 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

  Issue Randomize
  before generating random number. It seeds from the current time

----------
Rajani

 
Old January 6th, 2005, 10:58 PM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

Code:
Dim DummyRandomValue 
Randomize
DummyRandomValue = Rnd 'Rnd generates a random number between 0 -1
Response.Write(DummyRandomValue)
FYI, randomize uses the system clock to generate different seed for Rnd function on each occasion.

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 9th, 2005, 02:44 PM
Registered User
 
Join Date: Jan 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great, thanks for the help!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Random recordset kumiko SQL Server 2005 3 March 8th, 2008 12:03 PM
Random Picture mani_he Pro PHP 7 February 5th, 2005 12:56 PM
random generator starsailor Javascript 1 December 7th, 2004 12:16 AM
help with random records ps124 ASP.NET 1.0 and 1.1 Basics 0 March 14th, 2004 10:57 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.