ntropy ~trunk

Generate cryptographically secure pseudorandom data, compatible with BetterC, @safe, @nogc, and nothrow.


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

NTropy

This library provides a lightweight platform-independent interface to generate cryptographically secure pseudorandom data from system sources. NTropy is compatible with @safe, @nogc and nothrow, and can be compiled with BetterC compatibility.

Public methods in the source code have embedded documentation.

Usage

Fill a buffer with cryptographically secure random data:

import ntropy;

auto myBuffer = new ubyte[](32);
if(ntropy.generate(myBuffer)){
	//use `myBuffer`
}else{
	//error detected!
}

Generate a fixed amount of cryptographically secure random data:

import ntropy;

bool success;

short[14] myData = ntropy.generate!(short[14])(success);
if(success){
	//use `myData`
}else{
	//error detected!
}

int myInt = ntropy.generate!int(success);
if(success){
	//use `myInt`
}else{
	//error detected!
}

Supported platforms

Version identifier(s)Minimum versionImplementation
linux/AndroidKernel 3.17, glibc 2.25getrandom
OSX10.10CCRandomGenerateBytes
iOS8.0CCRandomGenerateBytes
TVOS/WatchOS/VisionOS(none)CCRandomGenerateBytes
WindowsVista / Server 2008BCryptGenRandom
FreeBSD12.0getrandom
OpenBSD2.1arc4random_buf
NetBSD10.0getrandom
DragonFlyBSD5.7getrandom
Hurd(unknown)getrandom
Solaris11.3getrandom
AIX(unknown)/dev/urandom
HaikuR1/beta5arc4random_buf
Cygwin2.7.0getrandom

Not all platforms have been tested. Pull requests to add new platforms, lower minimum system versions, or fix bugs are welcome.

BetterC compatibility

If you are using dub, then by default the library will compile without BetterC. To enable BetterC compatibility, select the yesBC configuration in your dub recipe.

See also

  • csprng-d inspired this project. It is a similar library but not as lightweight, and isn't actively maintained.
  • getrandom for Rust, whose documentation inspired this README.
Authors:
  • Aya Partridge
Dependencies:
none
Versions:
0.1.2 2025-Jan-01
0.1.1 2025-Jan-01
0.1.0 2025-Jan-01
~trunk 2025-Jan-01
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 4 downloads this week

  • 5 downloads this month

  • 6 downloads total

Score:
0.4
Short URL:
ntropy.dub.pm