1

I have been fiddling with this problem for a while of generating an array of a compile time constant size containing unique random integers up to a compile time constant value. I have a nice templated rng, that I butchered from a paper, but haven't figured out the rest. This is probably a stupid question but - is this endeavour theoretically possible in c++, or have I missed something silly?

Edit: if it is possible please no spoilers

user3684792
  • 2,542
  • 2
  • 18
  • 23
  • so, you want an array to have randomly-generated values at compile-time? – kmdreko Sep 26 '16 at 23:05
  • yes indeed i do – user3684792 Sep 26 '16 at 23:06
  • I'd rather did it with some shell script + `make(1)` – Oleg Andriyanov Sep 26 '16 at 23:08
  • I am a metaprogramming noob. – user3684792 Sep 26 '16 at 23:08
  • 3
    you could build something off of this answer: http://stackoverflow.com/questions/11498304/generate-random-numbers-in-c-at-compile-time – kmdreko Sep 26 '16 at 23:08
  • If you have a templated RNG then you're pretty much done, aren't you? Just value-initialise the array – Lightness Races in Orbit Sep 26 '16 at 23:09
  • ok, thanks @LightnessRacesinOrbit I just wanted to know it was possible. The issue with the rng is that it is self seeding (not unlike the linked answer). So I needed a recursive solution to build the array and was messing it up. Too tired to figure it out now, just wanted to know if I was wasting my time as I haven't readily found similar endeavours online – user3684792 Sep 26 '16 at 23:12
  • Well don't quote me on it; I don't generally have time for gimmicks like this, so I've never tried it ;) But I can't think of any reason it shouldn't work (FSVO "work"; I can't see how useful it'd be). – Lightness Races in Orbit Sep 26 '16 at 23:12
  • I've done this with Visual C++ 2015, using timestamp macros for seeding the compile-time RNG implemented with template metaprogramming. Seeding from char arrays relied on being able to access elements at compile-time, which is possible with VS2015, but not with previous versions, and I don't remember if I tried it with GCC. I pretty much abandoned the project as soon as I got it to work, because it didn't seem very useful. – Christopher Oicles Sep 26 '16 at 23:30
  • I will let you know if I find a use.... – user3684792 Sep 26 '16 at 23:52
  • Yeah, let me know. And don't get me wrong, I'm all for cool but useless. It's kinda like climbing a mountain just to reach the summit. – Christopher Oicles Sep 27 '16 at 00:33

0 Answers0