Computer Science Canada

Help with randint in looping

Author:  ExcuisiteSquid [ Wed Mar 27, 2013 5:02 pm ]
Post subject:  Help with randint in looping

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>


What is the problem you are having?
<Answer Here>


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>

Author:  Raknarg [ Wed Mar 27, 2013 5:22 pm ]
Post subject:  RE:Help with randint in looping

Try that again

Author:  Cancer Sol [ Wed Mar 27, 2013 5:52 pm ]
Post subject:  Re: Help with randint in looping

What exactly are you having trouble with your randint within the loop?
I'll just take a guess here, but it's probably not what you want.
What I used to have trouble with is having the randint generate a new random value each time the loop restarts.
I'm not sure how to show it in turing, I'll just post the code in C++.
c++:

#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;

int randRange (int low, int high)
{
        return rand() % ( high - low + 1 ) + low;
}

int main ()
{
        srand(time(NULL));
        for (int i=0; i<100; i++)
        {
                cout << randRange (1, 20) << endl; //Output: Random integer between 1 to 20
        }
}

Maybe someone who's nice can help translate that to Turing Wink
If I even did it right lol. I read that in Alex Allain's c++ ebook a week ago, but I haven't used it for quite some time.

Author:  Raknarg [ Wed Mar 27, 2013 6:32 pm ]
Post subject:  RE:Help with randint in looping

Yeah he probably made a mistake in the template, I'm just waiting for him to update


: