d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Very Easy Java Question, Explain Like I'm 4 > Real Beginner
Add Reply New Topic New Poll
Member
Posts: 20,715
Joined: Mar 1 2008
Gold: 82.00
Apr 28 2013 02:32pm
nbDes= Number of Dices that need to be displayed
affichageDes=Code to display it in the HTML
tDes= table from 1 to 12, each of them given the value of a dice (it's a .gif). 1 to 6 = red dice , 7 to 12 = blue dice.
rand1= random equation to get a dice from 1 to 6 (red dices only)

Code


if(rouge==true){
for(i=0;i<nbDes;i++){
 affichageDes+=tDes[rand1];



My problem is: My loop works, if I select 3 red dices, there's 3 red dices. The only thing that don't work is that they're all the same. They randomize, but they'll always be the same number.
Example: I want 5 dices, I'll have 5, but they'll all be on the #2 side. Whenever I load the page back, they'll be any number from 1 to 6, but never 2 dices will be different. I need random numbers for each dice.


I know it's probably an easy fix, I'm all new to this and somehow it's been bugging me for awhile now. How do I fix this?
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Apr 28 2013 02:50pm
rand1 isn't changing in your loop so they're all the same. replace the variable with the method that creates a random number and you should be good to go.
Member
Posts: 20,715
Joined: Mar 1 2008
Gold: 82.00
Apr 28 2013 03:01pm
Quote (carteblanche @ Apr 28 2013 03:50pm)
rand1 isn't changing in your loop so they're all the same. replace the variable with the method that creates a random number and you should be good to go.


Holy shit. Thanks man
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll