0

Get the error when I push a action on my contract on the local testnet:

enter image description here

But if I remove this code from the action I called, there is no problem:

enter image description here

class urng:

enter image description here

Does anyone know what caused this?I just want to use a random seed in my contract to shuffle my array.

3
  • 1
    Welcome @Lich! It's much better practice to copy & paste (and format) code and error messages instead of posting images/screenshots. See meta.stackoverflow.com/questions/285551/…
    – Don
    Mar 17, 2019 at 17:08
  • 1
    Oh, I am sorry, I am asking questions on here for the first time. I will pay attention next time, thank you for your reminder!
    – Lich
    Mar 18, 2019 at 2:11
  • all good, just giving you a head's up. :)
    – Don
    Mar 18, 2019 at 22:44

2 Answers 2

0

Probably your urng class is somehow causing an issue, can you confirm that the following code does or does not work?

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
shuffle (foo.begin(), foo.end(), std::default_random_engine(seed));

Also, I don't know what you are programming, but any random number generated in this way is not safe. It will be deterministic and can not be used to protect against people calculating a result for a game in advance or something like this. To learn about how to do random numbers, see How can I generate random numbers inside a smart contract?

1
  • You are right, I found the cause of the problem while debugging the source code of std::shuffle, I should not return a constant in urng::operator()(), this will cause an infinite loop inside the std::shuffle. Since eosio.cdt does not support <random>, so I have to implement a URNG myself using the seed provided by the user.
    – Lich
    Mar 18, 2019 at 2:17
0

I assume it's because std::shuffle and also some of the internally used types are making use of multiple iterations.

So depending on the implementation of std:shuffle and the internally used types there are multiple iterations per array-element in your foo-array, which consumes the CPU.

1
  • Yes, I should not return a constant in urng::operator()(), this will cause an infinite loop inside the std::shuffle.
    – Lich
    Mar 18, 2019 at 2:22

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .