https://github.com/n8tbyte/buuid
A lightweight Go package for generating random strings, numbers, and unique IDs quickly and easily.
https://github.com/n8tbyte/buuid
Last synced: 5 days ago
JSON representation
A lightweight Go package for generating random strings, numbers, and unique IDs quickly and easily.
- Host: GitHub
- URL: https://github.com/n8tbyte/buuid
- Owner: n8tbyte
- License: mit
- Created: 2025-05-21T18:53:14.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-22T17:21:08.000Z (about 1 year ago)
- Last Synced: 2026-02-27T21:35:15.728Z (4 months ago)
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buuid - Simple Random Generator Package

[](LICENSE)
A lightweight Go package for generating various types of random values with simple APIs.
## Features
- Generate random strings with custom character sets
- Create random integers within a range
- Generate random floating-point numbers
- Produce unique IDs with timestamp components
- Thread-safe operations
## Installation
```bash
go get github.com/naruepanart/buuid
```
## Usage
### Random Strings
```go
import "github.com/naruepanart/buuid"
// Available character set flags:
// buuid.R_NUM - Numbers only (0-9)
// buuid.R_UPPER - Uppercase letters only (A-Z)
// buuid.R_LOWER - Lowercase letters only (a-z)
// buuid.R_All - All characters (0-9, A-Z, a-z)
// Generate 10-character random string with numbers and lowercase letters
randomStr := buuid.String(buuid.R_NUM|buuid.R_LOWER, 10)
// Generate 6-character random string with all character types (default length)
randomStr := buuid.String(buuid.R_All)
```
### Random Numbers
```go
// Random integer between 0-100 (default)
num := buuid.Int()
// Random integer between 0-50
num := buuid.Int(50)
// Random integer between 10-20
num := buuid.Int(10, 20)
```
### Random Floating-Point Numbers
```go
// Random float with 2 decimal places, between 0.0-100.0
f := buuid.Float64(2)
// Random float with 3 decimal places, between 0.0-50.0
f := buuid.Float64(3, 50)
// Random float with 4 decimal places, between 10.0-20.0
f := buuid.Float64(4, 10, 20)
```
### Unique IDs
```go
// Numeric ID combining timestamp and random component
id := buuid.NewID() // e.g., 1651234567890123456
// Hexadecimal string version of NewID()
hexID := buuid.NewStringID() // e.g., "16f3a5b7c8d9e0f1"
// Formatted timestamp ID with random suffix
seriesID := buuid.NewSeriesID() // e.g., "2023052312453000000123456"
```
## Performance
The package uses crypto/rand for secure random generation by default, with fallback to time-based randomness if crypto/rand fails.
## License
MIT License. See [LICENSE](LICENSE) for details.