#random number generators

1 messages · Page 1 of 1 (latest)

frail chasm
frail chasm
# frail chasm

Please help

I dont understand what they mean by "created and seeded everytime"

fervent tangle
# frail chasm Please help I dont understand what they mean by "created and seeded everytime"

it means that everytime the function is called, the pseudo-random number generator also generates new number, so to fix it you can create a global boolean variable to mark it whether the function is already ever called or not, if it is, then don't run the generator again, otherwise run

bool called = False;
int getCard()
{
      if (!called)
      {
           called = true;
           std::mt19937 mt{std::random_device{}() };
           std::uniform_int_distribution card{ 1, 52 };
            return card(mt);
      }
}
frail chasm
fervent tangle
frail chasm
frail chasm
fervent tangle
# frail chasm What does being seeded mean jn dummy terms?<@985005820708278296>

seed means a list of number the generator can generate, and we usually assign a number to the generator to tell it what seed number we want
for example seed 1 is 1-10
seed 2 is 11-20
and so on
we seed also cuz for the list of numbers generated will be the same, without a seed number, the list of number generated will be random

frail chasm
fervent tangle
frail chasm
frail chasm
grizzled badger
#

There is no seed in that image, it is set somewhere in the random_device() function probably

frail chasm
grizzled badger
#

yes that is true

#

thats why you dont want to call it multiple time

grizzled badger
#

a seed is not a list of numbers the computer can generatr

#

a seed is like a base number used to generate numbers
it can be any numbers like 474994947389474

#

usually people use something like thr current time of the system, since it changes all the time its a good way to ensure your generates numbers will not be the same

frail chasm
grizzled badger
frail chasm
grizzled badger
frail chasm