0

I'm trying to generate random numbers but with this seed

int rdtsc()         
{
    __asm__ __volatile__("rdtsc");
}

But when I try to compile I get this error:

error C2065: '__asm__' : identificador no declarado
error C2146: error de sintaxis : falta ';' delante del identificador '__volatile__'

What do I have to do? Is there another way to generate true random numbers, rather than via time(null)?

plasmacel
  • 8,183
  • 7
  • 53
  • 101
Deivbid
  • 393
  • 2
  • 6
  • 15
  • 2
    I expect you're trying to use inline assembly in an x64 build, which Visual Studio does not support (for some unknown reason). Note that you can not generate "true" random numbers (without some hardware support) - you can only ever generate *pseudo-random* numbers. – Paul R May 24 '17 at 07:51
  • 1
    Use random_device or lookup rand_s on msdn.microsoft.com. – user515430 May 24 '17 at 08:10
  • 2
    That is gcc syntax. If you use visual studio then it is ` __asm rdtsc;` – Hans Passant May 24 '17 at 10:59
  • 1
    Please don't use the `random` tag, `rdtsc` has nothing to do with randomness. – plasmacel May 25 '17 at 18:15
  • That asm would not be safe even with a compiler that could compile it (gcc/clang/ICC). You need output operands. – Peter Cordes Aug 18 '18 at 15:52

1 Answers1

3

The 64-bit version of Visual C++ does not support inline assembly, but it does provide built in functions for most special instruction, like rdtsc.

So no need to write that code yourself.


And even if you are using the 32-bit compiler, the assembly syntax isn't

__asm__ __volatile__("rdtsc");

but just

__asm rdtsc
Bo Persson
  • 90,663
  • 31
  • 146
  • 203