• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

random numbers, returns a negative number?

 
matthew christensen
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey guys im new to coderanch.

im having some problem wit this code. its generating a random number, but its negative and i cant figure out why. im writing a text-based-rpg-combat-system.

it gets its variables from this class

not sure what the big deal is, no compiler errors come up
im using netbeans 6.9.1 and jdk 6_21
 
fred rosenberger
lowercase baba
Bartender
Posts: 12084
29
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not sure why you say you're getting negative numbers...taking the least amount of your code as possible:

I didn't get a negative value once.

I'd suggest putting more S.o.p.'s in your code and see what it's really doing.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed; there's no way the random number itself is negative.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Mohamed Omar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry if this is a late reply, I saw this post just now.

the problem with your code is that your subtracting the dmg (which is already negative) from AIhp resulting an increase in the AIhp. you should change it to


 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mohamed Omar, welcome to JavaRanch And thank you for finally finding the error
 
Mohamed Omar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic