I'm making a little program for D&D combat, and I am in need of an random function for making integer... #include <cstdlib> #include <ctime> #include <iostream> using namespace std; int RandInt(int a,int b) { srand(time(0)); return a + rand() % (b - a + 1); } int x = RandInt(1,6); Code (markup): I'm using this function, but the problem is that during one executing it alway displays the same value, in order to change the value i have to re-run the program, and it is not acceptable,so plz help me...
#include <stdio.h> #include <stdlib.h> int main(void) { int random_number; srand(time(0)); random_number = rand(); printf("%d\n", random_number); return 0; } Code (markup):