• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Khatharr

Does C++ <random> lib require seeding?

9 posts in this topic

I've implemented a function:

bool doesCustomerArrive(int custPerHour) {
  if(custPerHour > 60) {return true;}
  static default_random_engine generator;
  float custPerMinute = (float)custPerHour / 60;
  bernoulli_distribution distribution(custPerMinute);
  return distribution(generator);
}

Which I'm using in a simulation. I iterate custPerHour, starting from 1, and run the thing 6000 times per iteration, doing some calculations until a specific result is met. My problem is that the program is producing the exact same unusual results every time it's run, which immediately makes me think that I've either failed to seed the randomizer or else just set this up wrong. I thought this new set of random functions didn't need seeding, and I don't see anything wrong with my algorithm. Where am I screwing up here?

 

Specifically, the problem results are:

39 CPH for 100 hours = 2016 customers (expected 3900)

40 CPH for 100 hours = 1986 customers (expected 4000)

 

The results are the same every time.

Edited by Khatharr
0

Share this post


Link to post
Share on other sites

Crud. (Why the hell don't they make the default call a chrono function?)

 

Thanks, Promit.

Because in a vast majority of the cases you do not want to initialize it with a value from chrono, but from a pre-existing value loaded from previously saved data. In addition, the moto of the language designers and library writers is "do as little as possible.", initializing with 1u is doing as little as possible. While calling a potentially expensive time function is not.

Edited by Washu
2

Share this post


Link to post
Share on other sites

Because in a vast majority of the cases you do not want to initialize it with a value from chrono, but from a pre-existing value loaded from previously saved data. In addition, the moto of the language designers and library writers is "do as little as possible.", initializing with 1u is doing as little as possible. While calling a potentially expensive time function is not.

Vast majority? I've only seen a limited number of cases where it made sense to use a specific seed. Why would specifically seeded sequences be the majority case?

More importantly, if we want to talk about conservative design, why does it have a default argument at all? How often do I want my seed value to be 1u?

(raging at my android osk right now omg) Edited by Khatharr
0

Share this post


Link to post
Share on other sites

Because reproducibility is desirable, while non-reproducibility is undesirable.

// See, for instance, http://openmd.org/?p=257

Think how hard debugging would be if you couldn't guarantee the same execution path of your program.

 

Besides, even if you were fine with non-reproducibility, seeding with time functions is often a bad idea -- at least, you'd need a high resolution timer.

As an alternative, you can do the following:

std::random_device rdev{}; // ASSUMPTION: your implementation / target platform actually guarantees this is random
std::default_random_engine e{rdev()}; // seed with the aforementioned source of randomness

 

For more, read this:

http://isocpp.org/files/papers/n3551.pdf

1

Share this post


Link to post
Share on other sites

I've only seen a limited number of cases where it made sense to use a specific seed. Why would specifically seeded sequences be the majority case?

The motivation for writing <random> did not come from game developers (most of whom live in the NIH world anyway) but from the scientific and engineering crowds with their models and simulations. For these purposes it's very important to be able to reproduce exactly the same pseudorandom sequences for different runs as various other parameters are adjusted.

 
Ah, okay. That sort of makes sense. TBH it kind of sucks that they wouldn't consider both groups, though, and throw us a bone by way of a typedef or something.
 

You'll notice that most of the engines in <random> require a seed vector with size greater than 1 (only the LCG can use a seed vector of size 1). The only way you can have a common constructor signature across all the engines is to have a zero-argument constructor, and that's gotta be a forwarding constructor with a default initializer value. The only reasonable numbers for a default are 0 and 1, and the committee chose 1. Note that the default initializer seed vector for engines other than the LCG is generally a sequence generated by the default LCG initialized to 1.


Okay, I get the common signature part, but I don't get zero-argument part. Is there an engine that requires no seed, or are they just thinking that there may be one added in the future? Edited by Washu
0

Share this post


Link to post
Share on other sites

I've only seen a limited number of cases where it made sense to use a specific seed. Why would specifically seeded sequences be the majority case?

The motivation for writing <random> did not come from game developers (most of whom live in the NIH world anyway) but from the scientific and engineering crowds with their models and simulations. For these purposes it's very important to be able to reproduce exactly the same pseudorandom sequences for different runs as various other parameters are adjusted.

 
Ah, okay. That sort of makes sense. TBH it kind of sucks that they wouldn't consider both groups, though, and throw us a bone by way of a typedef or something.

You have a constructor you can pass a chrono value to. Exactly what more do you need?

You'll notice that most of the engines in <random> require a seed vector with size greater than 1 (only the LCG can use a seed vector of size 1). The only way you can have a common constructor signature across all the engines is to have a zero-argument constructor, and that's gotta be a forwarding constructor with a default initializer value. The only reasonable numbers for a default are 0 and 1, and the committee chose 1. Note that the default initializer seed vector for engines other than the LCG is generally a sequence generated by the default LCG initialized to 1.


Okay, I get the common signature part, but I don't get zero-argument part. Is there an engine that requires no seed, or are they just thinking that there may be one added in the future?

Some of the RNGs, such as the ranlux48 generator, have a default constructor. This constructor invokes the underlying base ranlux48 generator with its default arguments, which is 1u, which is then passed to the LCE, the LCE is then used to generate the default seed of the ranlux48 base generator, which in turn is used by the ranlux48 generator.

Vast majority? I've only seen a limited number of cases where it made sense to use a specific seed. Why would specifically seeded sequences be the majority case?

So you've never wanted to be able to do replays? Or generate the same terrain more than once? Or load up save games and have them behave the same? There are plenty of cases where you want to be able to replicate the same random set of numbers in a game. Edited by Washu
2

Share this post


Link to post
Share on other sites


Vast majority? I've only seen a limited number of cases where it made sense to use a specific seed. Why would specifically seeded sequences be the majority case?

So you've never wanted to be able to do replays? Or generate the same terrain more than once? Or load up save games and have them behave the same? There are plenty of cases where you want to be able to replicate the same random set of numbers in a game.

 

 

Replays and terrain generation are the two cases I was thinking of. In both cases you're re-using a seed you got from an entropic or pseudo-entropic source, though.

 

Loading a save and getting identical behavior from the randomizer isn't something I like. It's not random and it encourages prng prediction cheats.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0