std.random.uniform(1, 101) crashes. Why, and workaround.

Brother Bill brotherbill at mail.com
Fri Jul 25 01:04:31 UTC 2025


 From "Programming in D" book:

import std.stdio;
import std.random;

     void main() {
     	int number = uniform(1, 101);

     	writeln("Edit source/app.d to start your project.");
     }

     Running it generates:
     phobos64.lib(random_6ea_855.obj) : error LNK2019: unresolved 
external symbol BCryptGenRandom referenced in function 
_D3std6random__T15bcryptGenRandomTmZQuFNbNiNeJmZb
     
C:\Users\broth\AppData\Local\Temp\.rdmd\rdmd-app.d-99D1A2446E2CA5089AD8A9B31EA74F07\app.exe.tmp : fatal error LNK1120: 1 unresolved externals
     Error: linker exited with status 1120
            C:\Program Files\Microsoft Visual 
Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\HostX64\x64\link.exe /NOLOGO "C:\Users\broth\AppData\Local\Temp\.rdmd\rdmd-app.d-99D1A2446E2CA5089AD8A9B31EA74F07\objs\app.exe.obj" /OUT:"C:\Users\broth\AppData\Local\Temp\.rdmd\rdmd-app.d-99D1A2446E2CA5089AD8A9B31EA74F07\app.exe.tmp"  /DEFAULTLIB:phobos64  /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\lib\x64" legacy_stdio_definitions.lib /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.26100.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\lib\10.0.26100.0\um\x64"
     Error: undefined reference to `BCryptGenRandom`
            referenced from `nothrow @nogc @trusted bool 
std.random.bcryptGenRandom!(ulong).bcryptGenRandom(out ulong)`
            perhaps a library needs to be added with the `-L` flag 
or `pragma(lib, ...)`

      *  The terminal process 
"C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe 
-Command & 'rdmd' 'c:\dev\D\21 - 
30\c27_a_do_while_loop\source\app.d'" terminated with exit code: 
1.

Is there another way to get a random integer between 1 and 100?


More information about the Digitalmars-d-learn mailing list