Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Nim library to generate random numbers and random ranges of bytes using the system's PRNG.

License

NotificationsYou must be signed in to change notification settings

euantorano/sysrandom.nim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A simple library to generate random data, using the system's PRNG.

The following sources of randomness are used depending on platform:

Installation

sysrandom can be installed using Nimble:

nimble install sysrandom

Or add the following to your .nimble file:

# Dependenciesrequires "sysrandom >= 1.1.0"

Usage

import sysrandom## Make sure to close the `/dev/urandom` file on posix or close the DLL handle on Windows after you're finished generating random datadefer:closeRandom()## Fill a buffer with x random bytesvar buffer=newSeq[byte](20)getRandomBytes(addr buffer[0],len(buffer))## Create an array of 10 random bytes (`array[10, byte]`)let randomBytes=getRandomBytes(10)echo"Generating 10 random bytes:",repr(randomBytes)## Get a random unsigned 32 bit integer (`uint32`) in the range 0..0xfffffffflet randomUint32=getRandom()echo"Random integer:", randomUint32## Generate a random string based upon a 32 byte array of random values, base 64 encodedlet randomString=getRandomString(32)echo"Random string:", randomString

About

A Nim library to generate random numbers and random ranges of bytes using the system's PRNG.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp