Hello!
I've read that batch %RANDOM% is not very random.
I thought it would be nice to have a .exe written in C programming language, which will return random number upon execution.
I've downloaded and installed Code::Blocks and tried different examples from the web, but all of them aren't producing anything good, they are using srand(time(NULL)); and rand();.
I've read that you need to create your own random number generator with example:
#define random(value) ((int)(((double)(rand())*(value))/(RAND_MAX+1.0)))
I can't figure how it works.
Can you, please, show me a C code which will generate random numbers?
Many thanks!
Batch random number through C executable
Moderator: DosItHelp
Re: Batch random number through C executable
Well last I checked this wasn't a C programming forum.
Simple enough to call out to Powershell from a batch file and assign it to a variable.
Code: Select all
FOR /F "delims=" %%G IN ('powershell "GET-RANDOM"') do set _rand=%%G
Re: Batch random number through C executable
I suggest you to review this thread. There is an assembly source program to use RDRAND CPU instruction in order to generate random numbers and its ready-to-use .exe program.
Antonio
Antonio
Re: Batch random number through C executable
While I agree with Squashman that this is not a C forum, just as an aside: Don't use the standard C functions to generate pseudorandom numbers. The generated values of rand() are as predictable as the values of the %random% variable. If you want to have a C-like functionality on Windows, rather use the BCryptGenRandom() API. There are plenty of examples how to use it.
Steffen
(FWIW: If you continue to fire and forget your threads, whithout giving feedback to the volunteers if you even read their responses, I'm going to stop answering your questions. Just saying.)
Steffen
(FWIW: If you continue to fire and forget your threads, whithout giving feedback to the volunteers if you even read their responses, I'm going to stop answering your questions. Just saying.)
Re: Batch random number through C executable
Thanks, everyone!
The Powershell solution is what I need.
Assembly program looks interesting, I'll read about it.
The Powershell solution is what I need.
Assembly program looks interesting, I'll read about it.
Sorry about that. I just got used to others forums, where when they answer your question, and you reply "Thank you!", they complain about flooding the forums with useless posts.