Prng into static class.

How do I make this a static class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
    srand(time(0));

    for(int x = 1; x<2500;x++){
        cout << 1+(rand()%2000) << endl;
    }
}
static class isn't a thing in C++. What are you trying to organize into a class? If it's just a function, why not just leave it as a function? Did you learn C# or Java before this? (sorry for all the questions at once)

Edit: Judging by your title, you're trying to make (pseudo) random number generator, what functionality do you want that rand() doesn't provide?
Last edited on
Instead of a static class he could make a class where all the methods are public static like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//header
class SomeClass
{
    public:
        static void someFunction();
};

//implementation
void SomeClass::someFunction()
{
    //do something
}

//main
#include "SomeClass.hpp"

int main()
{
    SomeClass::someFunction();
}


http://www.cplusplus.com/doc/tutorial/templates/
Last edited on
Or he could use a namespace.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//header
namespace SomeNamespace
{
	void someFunction();
};

//implementation
void SomeNamespace::someFunction()
{
	//do something
}

//main
#include "SomeNamespace.hpp"

int main()
{
	SomeNamespace::someFunction();
}
Topic archived. No new replies allowed.