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

H. S. Teoh hsteoh at qfbox.info
Fri Jul 25 02:45:14 UTC 2025


On Fri, Jul 25, 2025 at 01:04:31AM +0000, Brother Bill via Digitalmars-d-learn wrote:
> 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
[...]

You might want to check your compiler installation. Linker errors from
the standard library usually mean one or more parts of the compiler
toolchain wasn't installed correctly.  Or you may have a stale D
installation from before, and for whatever reason the current compiler
is wrongly picking up older versions of the standard library, which is
incompatible with the current version.

Maybe run dmd with -v and look at the path(s) it's using for the
standard libraries and runtime files.  If these don't look like where
the (current) compiler is installed, it's probably why you're getting
linker errors.


T

-- 
Creativity is not an excuse for sloppiness.


More information about the Digitalmars-d-learn mailing list