パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.2.0

rnd

Random 用の拡張メソッドとヘルパー、およびグローバルにアクセス可能なインスタンス。例:rnd(10)、rnd.getItem(list)、rnd.getBit(0.8)。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1410
いいね数
33
Pub ポイント
160

パッケージをインストール

flutter pub add rnd

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

rnd パッケージは、Dart の Random クラスに拡張メソッドとユーティリティ関数を追加し、簡潔で読みやすいコードのためにグローバルにアクセス可能なランダムインスタンスを提供します。rnd(10) による乱数の生成、rnd.getItem(list) によるリストからのランダムなアイテム選択、rnd.getBit(0.8) によるバイアス付きビットの生成といった簡単な操作が可能になります。ゲーム、シミュレーション、データシャッフル用途に最適化されており、ボイラープレートを必要とせずに一般的なランダム化タスクを簡素化します。パッケージは軽量で、すべての主要プラットフォームと互換性があります。

用途

  • ゲーム開発
  • ランダムなアイテム選択
  • Simulations
  • データシャッフル
  • プロシージャルコンテンツ生成

主な機能

  • グローバルなランダムインスタンス
  • Random に対する拡張メソッド
  • rnd(10) のような簡単な構文
  • 重み付き選択のサポート
  • クロスプラットフォーム互換性

適している対象

  • 迅速なランダムユーティリティを求める開発者
  • ゲームおよびアプリ作成者
  • プロトタイピングとテスト

注意事項

  • 暗号化ランダムネスには適していません
  • セキュリティ上重要な用途に限定
  • 基本的なランダム化の概念を理解している必要がある

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

rnd package

Makes working with random values in Dart / Flutter easier:

  1. It provides an easy to access, global instance of Random.
  2. It adds helpful extension methods to Random.

Global instance

To make it easy to set up and propagate a Random instance throughout your app, the rnd package exposes a global instance via the rnd property. This makes generating a random value as simple as:

import 'package:rnd/rnd.dart';
rnd(10); // random double between 0-10
rnd.getBool(0.8); // 80% chance to get true

You can also get and set the seed for the global instance via rndSeed.

Extension methods on Random

Adds the following methods to all instances of Random. Read the docs for more info.

  • getInt(min, max, {curve}) // see "Curves" below
  • getDouble(min, max, {curve})
  • getBool(chance)
  • getBit(chance) // 0 or 1
  • getSign(chance) // -1 or 1
  • getDeg() // 0-360
  • getRad() // 0-2pi
  • getColor({...}) // see docs for params
  • getItem(list, {remove, curve})
  • shuffle(list, {copy}) // randomize list

It also defines a call method, which lets you get a random double value by calling a Random instance directly:

Random myRandom = new Random();
print(myRandom()); // double between 0-1
print(myRandom(10)); // 0-10
print(myRandom(5,10)); // 5-10

This pairs well with the global instance for quickly getting random values:

new Point(rnd(maxX), rnd(maxY))

Curves

The getDouble, getInt, and getItem methods support a curve param which transforms the value distribution. For example:

rnd.getInt(0, 100, curve: Curves.easeIn)

This would favor values nearer to 0, whereas easeOut would favor values nearer to 100. The included example app visualizes the effect of different curves.

Hue

The included Hue class provides named hue values for use with getColor. For example:

rnd.getColor(hue: Hue.red); // red, green, blue, yellow, cyan, magenta

カテゴリー

ソースリポジトリ

このパッケージを使用しているプロジェクト