An implementation of Weighted Randoms using Kotlin

Overview

WeightedRandoms-Kotlin

An implementation of Weighted Randoms using Kotlin

Description

The WeightedRandoms series was originally made to help me with some role-playing games I was working on. I wanted to randomly choose an item from a list but to do so with unequal chances that the item I wanted would be returned. For example if I wanted to determine a list of NPCs in a village of Amazons, the chance that each NPC would be female is more likely than if they were to somehow be men.

In this case, I might write some code like this

  val list = Randomizer<String>(
    arrayOf(
      Item("Male", 1.0f),
      Item("Female", 4.5f),
    )
  )

  // Retrieve five weighted random items
  list.next(5)
    .let { it.map { s -> s.value } }
    .also { println(it) }


  // Might return logical results like these
  // ["Male", "Female", "Female", "Female", "Male"]
You might also like...
Simple use of Micronaut + Kotlin, implementation of UserContext

Micronaut 3.1.4 Documentation User Guide API Reference Configuration Reference Micronaut Guides Feature jdbc-hikari documentation Micronaut Hikari JDB

OO Boot Camp reference implementation for Jordanian client in Kotlin in January 2022

oo_boot_camp_2022-01-24_kotlin Copyright (c) 2022 by Fred George May be used fre

Kotlin implementation of basic blockchain technology.

kotlin-blockchain Kotlin implementation of basic blockchain technology. Features: Data and storage Mining and block validation Hashing and previous bl

A basic Kotlin implementation of Facebook's memcache lease functionality.

Liftgate Lease A basic Kotlin implementation of Facebook's memcache lease functionality. How it works If the cache key is empty or has been invalidate

Archimedes's implementation for the Java Virtual Machine (JVM)

Archimedes Give me a place to stand, and I shall move the earth. Archimedes's implementation for the Java Virtual Machine (JVM) Building From Source T

The RuneTopic game server implementation that hosts and processes a game world.

RuneTopic Game Server The RuneTopic game server implementation that hosts and processes a game world. Setup Guide You can host a game server with Dock

The RuneTopic lobby server implementation that hosts and processes a lobby.

RuneTopic Lobby Server The RuneTopic lobby server implementation that hosts and processes a lobby. Setup Guide You can host a lobby server with Docker

Test Case Implementation From Nutrition-Framework
Test Case Implementation From Nutrition-Framework

Android Architecture Blueprints v2 Android Architecture Blueprints is a project to showcase different architectural approaches to developing Android a

Test Case Implementation From Nutrition-Framework
Test Case Implementation From Nutrition-Framework

About This Project (work-in-progress 👷 🔧️ 👷‍♀️ ⛏ ) Test Case Implementation Dari Nutrition Framework Version Release This Is Latest Release ~ Beta

Owner
Brielle Harrison
Brielle Harrison
An implementation of MediatR on JVM for Spring using Kotlin coroutines

Kpring MediatR In this project, an attempt has been made to implement the mediator pattern on the JVM with simplicity using Kotlin with native corouti

Mahdi Bohloul 4 Aug 6, 2022
🌱 A test implementation of a Minecraft server using RESTful API taking advantage of the interoperability between Kotlin and Java.

?? Norin A test implementation of a Minecraft server using RESTful API taking advantage of the interoperability between Kotlin and Java. This project

Gabriel 1 Jan 4, 2022
Multiplatform HTTP-Client implementation using Ktor

Kotlin Multiplatform HTTP-Client using Ktor Simple demonstration of a Ktor-based multiplatform HTTP-client in Kotlin Overview base submodule: common c

Jan Weidenhaupt 2 Oct 21, 2022
Saga pattern implementation in Kotlin build in top of Kotlin's Coroutines.

Module Saga Website can be found here Add in build.gradle.kts repositories { mavenCentral() } dependencies { implementation("io.github.nomisr

Simon Vergauwen 50 Dec 30, 2022
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Dec 26, 2022
A Zero-Dependency Kotlin Faker implementation built to leave you fully satisfied

Satisfaketion A Zero-Dependency Kotlin Faker implementation built to leave you fully satisfied ?? ... With your fake data How to Install ?? Satisfaket

Ryan Brink 7 Oct 3, 2022
🗼 yukata (浴衣) is a modernized and fast GraphQL implementation made in Kotlin

?? yukata 浴衣 - Modernized and fast implementation of GraphQL made in Kotlin yukata is never meant to be captialised, so it'll just be yukata if you me

Noel 5 Nov 4, 2022
📌This repo contains the kotlin implementation of TensorflowLite Example Android Apps🚀

TensorflowLite Examples Kotlin This repo contains the kotlin implementation of TensorflowLite Example Apps here, which are mostly implemented in java

Sunit Roy 28 Dec 13, 2022
Kotlin implementation of WalletConnect v2 protocol for Android applications

WalletConnect V2 - Kotlin Kotlin implementation of WalletConnect v2 protocol for

WalletConnect 92 Jan 6, 2023
Jikan-ga-aru-server - Kotlin implementation of jikan-ga-nai timesheet tracker

An exercise in implementing the Timesheet tracker (https://github.com/ultish/jik

null 0 Jan 6, 2022