Skip to content

Pseudorandom Number Generator

quocdat402 edited this page Aug 26, 2022 · 6 revisions

Overview

PseudoRandom class provides an API for seeding Pseduo-Generated Random features.

Usage

Generating a pseudo-randomly number

Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. Returned values are chosen pseudorandomly with (approximately) uniform distribution from that range. When this method is first called, it creates a single new pseudorandom-number generator, exactly as if by the expression.

  public static double randomUnitNumberGenerator () {
        return random();
    }

Generating pseudo-randomly integers or floating point number

Returns a pseudorandomly chosen double or integer value between a specifed lowerBound and upperBound.

  public static double seedRandomDouble (double lowerBound, double upperBound) {
        return lowerBound + new Random().nextDouble(upperBound - lowerBound);
    }

  public static int seedRandomInt (int lowerBound, int upperBound) {
        return lowerBound + new Random().nextInt(upperBound - lowerBound);
    }

Note: lowerBound and upperBound must be positive and finite, lowerBound must be less than upperBound.

Randomly selecting an item from a list

Selectes an item from a list by pseudo-randomly generating an integer between 0 and the length of the list, and returning the element at this index.

  public static <T> T getRandomItem(List<T> items) {
        int lenItems = items.size();
        int i = seedRandomInt(0, lenItems);
        return items.get(i);
    }

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally