Movatterモバイル変換


[0]ホーム

URL:


menu
  1. Dart
  2. dart:math
  3. Random class
Random
description

Random classabstractinterface

A generator of random bool, int, or double values.

The default implementation supplies a stream of pseudo-random bits that arenot suitable for cryptographic purposes.

Use theRandom.secure constructor for cryptographic purposes.

To create a non-negative random integer uniformly distributed in the rangefrom 0, inclusive, to max, exclusive, usenextInt(int max).

var intValue = Random().nextInt(10); // Value is >= 0 and < 10.intValue = Random().nextInt(100) + 50; // Value is >= 50 and < 150.

To create a non-negative random floating point value uniformly distributedin the range from 0.0, inclusive, to 1.0, exclusive, usenextDouble.

var doubleValue = Random().nextDouble(); // Value is >= 0.0 and < 1.0.doubleValue = Random().nextDouble() * 256; // Value is >= 0.0 and < 256.0.

To create a random Boolean value, usenextBool.

var boolValue = Random().nextBool(); // true or false, with equal chance.

Constructors

Random([int?seed])
Creates a random number generator.
factory
Random.secure()
Creates a cryptographically secure random number generator.
factory

Properties

hashCodeint
The hash code for this object.
no setterinherited
runtimeTypeType
A representation of the runtime type of the object.
no setterinherited

Methods

nextBool()bool
Generates a random boolean value.
nextDouble()double
Generates a non-negative random floating point value uniformly distributedin the range from 0.0, inclusive, to 1.0, exclusive.
nextInt(intmax)int
Generates a non-negative random integer uniformly distributed in the rangefrom 0, inclusive, tomax, exclusive.
noSuchMethod(Invocationinvocation)→ dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString()String
A string representation of this object.
inherited

Operators

operator ==(Objectother)bool
The equality operator.
inherited
  1. Dart
  2. dart:math
  3. Random class
dart:math library

[8]ページ先頭

©2009-2025 Movatter.jp