Randomize is not connect with ds_list_shuffle

Reporter: fervi  |  Status: open  |  Last Modified: October 12, 2017, 04:53:27 PM

Hello.

The GMS Randomize affects the values created by ds_list_shuffle (they are random). Enigma randomize does not affect them. We always get the same value.

Example (if you have GMS and Enigma):
http://meshnet-users.tk/paste/p/homh/a.gmk

RobertBColton  
@fervi for reference:
random_shuffle(ds_lists[id].begin(), ds_lists[id].end());

int randomize() { return enigma::Random_Seed = mtrandom32(); }

It directly uses the C++ shuffle:
http://en.cppreference.com/w/cpp/algorithm/random_shuffle

https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real%20valued%20functions/randomize.html

fervi  

Thanks for reply

Unfortunately I am not a programmer in C ++, I can not verify the correctness of the code - I just noticed that it is working badly.

I know some non-optimal way to solve this problem.

But maybe someday someone will fix it and that's why I reported it ;)

RobertBColton  

Just to provide clarification to this ticket, the unit test is:

randomize();
global.player1_deck = ds_list_create();
ds_list_add(global.player1_deck,1);
ds_list_add(global.player1_deck,2);
ds_list_add(global.player1_deck,3);
ds_list_add(global.player1_deck,4);
ds_list_add(global.player1_deck,5);
ds_list_shuffle(global.player1_deck);

In GameMaker: Studio I get different results each execution of the game, but not if I comment out the first line calling randomize(), as you indicated:
image

I confirm that I can reproduce the issue with ENIGMA whereby even with the randomize() call I always get the same order over and over and over:
confirmed

The GameMaker: Studio documentation does make this clear that randomize() should be called during testing and debugging:
https://docs.yoyogames.com/source/dadiospice/002_reference/data%20structures/ds%20lists/ds_list_shuffle.html

I don't know what the behavior, in regards to randomize(), was in previous GameMaker versions:
http://gamemaker.info/en/manual#ds_list_shuffle

Regardless, ds_list_shuffle(...) is clearly not randomizing at all in ENIGMA.

RobertBColton  

@fervi Thanks, this is actually an easy one to fix with your reproducible.

Issue is, source I linked above random_shuffle is deprecated in C++14 and also we were never calling the random function for it. So not only does the random need fixed, it also needs to use std::shuffle instead.
https://meetingcpp.com/blog/items/stdrandom_shuffle-is-deprecated.html

I'll forward this to @JoshDreamland and take a look at it later.

Edit: Our Wiki should also clarify this behavior.

Please sign in to post comments, or you can view this issue on GitHub.