This site requires JavaScript, please enable it in your browser!
Greenfoot back
sunny
sunny wrote ...

2015/9/11

how can i generate random no. sequences like - __,5,15,20

sunny sunny

2015/9/11

#
i used for loop for this but it keep generating same sequence. again and again. i should be different.
for (int i = 0; i < NumQues; i++) 
        {
            
            num1 = Greenfoot.getRandomNumber(50);
            num2 = num1 + 5;
            num3 = num2 + 5;
            num4 = num3 + 5;
        }
Super_Hippo Super_Hippo

2015/9/11

#
What is 'NumQues'? If it isn't higher than 0, then the loop won't be executed. Maybe you should show everything related to it.
danpost danpost

2015/9/11

#
One major problem with using the 'for' loop is that the values will change 'NumQues' times without anything being done while they are set to values set prior to the final setting. In other words, the loop can be removed without changing the code. It is equivalent to this (provided 'NumQues' is greater than zero):
num1 = Greenfoot.getRandomNumber(50);
num2 = num1 + 5;
num3 = num2 + 5;
num4 = num3 + 5;
You say it generates the same sequence. This is vague without more information. Some examples of what you want it to generate might help as well.
You need to login to post a reply.