패키지, 저장소 및 앱 카테고리 검색

패키지 상세v0.2.0

rnd

Random용 확장 메서드 및 도우미, 그리고 전역적으로 접근 가능한 인스턴스입니다. 예: rnd(10), rnd.getItem(list), rnd.getBit(0.8).

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.4천
좋아요
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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트