Jump to content

Etzhel

Member
  • Posts

    28
  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by Etzhel

  1. int number_ex(int from, int to, const char *file, int line)
    {
    	// We only need (and want) to initialize the mersenne twister generator once
    	static std::random_device rd;
    	static std::mt19937 mt(rd());
    	static std::uniform_int_distribution<int> dist; // not too expensive to create, though
    
    	if (from > to)
    	{
    		int tmp = from;
    
    		sys_err("number(): first argument is bigger than second argument %d -> %d, %s %d", from, to, file, line);
    
    		from = to;
    		to = tmp;
    	}
    
    	// Set the range we'd like our distribution to be on, and generate the number
    	return dist(mt, std::uniform_int_distribution<int>::param_type(from, to));
    }

     

    • Good 1
    • Love 1
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.