Jump to content
×
×
  • Create New...

[C++11] number_ex fix


Recommended Posts

  • Premium

Hi all!

This is recommended for those who are testing or running on windows.

The reason for the error is that they have a 100% chance of dropp.

 

Based on the video, you can watch:

 

number_ex old version:

https://metin2.download/video/404cFTu02qN7zGDbO2RA8za82mHM6xzq/.mp4

 

number_ex fixed:

https://metin2.download/video/8084RGh8gld28tLTsoYfx1ITK5W1fWxC/.mp4

 

FIX:

#include <random>

int number_ex(int from, int to, const char* file, int line)
{
    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;
    }

    int returnValue = 0;

    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> distrib(from, to);

    if ((to - from + 1) != 0)
        returnValue = distrib(gen);
    else
        sys_err("number(): devided by 0");

    return returnValue;
}

 

  • Metin2 Dev 2
  • Love 10
  • Good 3

c++latest, latest libs...

Link to comment
Share on other sites

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));
}

 

Edited by Etzhel
  • Love 1
  • Good 1
Link to comment
Share on other sites

  • 1 year later...
  • Moon

For people who might want to use this nowadays, I tested the drops and the upgrade succes percentage and is not so good, very bad drops and a lot of failed upgrades with this uniform random, but even if you use the ymir's function you might have situations where upgrade succeeds in a row or failing in a row

  • Think 1
Link to comment
Share on other sites

  • Premium
Posted (edited)

I checked and apparently I misunderstood., but I'm intrigued by the discussion.

Edited by Mitachi
  • Not Good 1

My signature (yes, I'm a creative guy)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.


  • Metin2 Dev Github
  • Activity

    1. 7

      Wear (use) item only on specific map

    2. 4

      Python tool for analyzing average yang drop per hour in each map.

    3. 162

      Plechito - Halloween 2022

    4. 0

      disable quest esc

    5. 7

      Wear (use) item only on specific map

    6. 7

      Wear (use) item only on specific map

    7. 7

      Wear (use) item only on specific map

    8. 4

      max level exp

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.