Yes, I can see a couple of problems right now.
The path "C:\Windows\System32\msvcrt.dll" is not portable. System32 can actually be installed in any directory. As this is Windows API, the usual appropriate and valid technique is using a file name without full path. It should be resolved in 32-bit version on 32-bit system and 64-bit version on 64-bit system. However, this is not a source of your problem. I hope you also know that you cannot mix different instruction-set target architectures in the same process. The assembly may compile, but this would lead to a crash during run time.
As this is Windows API, you need to use
System.Runtime.InteropServices.StdCall
. This the default convention for Windows OS calls, so you can simply omit this parameter. See
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.callingconvention.aspx[
^]. Most likely, the problem you observe is due to wrong calling conventions.
Why not staying with platform-portable solution by using the .NET class
System.Random
,
http://msdn.microsoft.com/en-us/library/system.random.aspx[
^]? Well, some say that
statistical quality of this generator is not perfect, but what tells you that msvcrt.dll
rand
is any better?
For example, take a look at this CodeProject articles:
Simple Random Number Generation[
^],
Pitfalls in Random Number Generation[
^].
—SA