npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

randomicsjs

v1.1.2

Published

um módulo para executar operações randômicas com listas

Downloads

4

Readme

RandomicsJS

Um pequeno módulo javascript para ajudar a fazer operações aleatórias com listas.

Uso

Com o npm instalado no seu computador digite: npm i randomicsjs No seu Javascript:

const randomics = require('randomicsjs')
const { basic, choice, choices, probs, shuffle } = randomics 

Ao todo são 5 métodos:

basic: (min: number, max: number, inclusive?: boolean) => number;
choice: (collection: any[], responses?: number, repeat?: boolean) => any;
choices: (collection: any[], weight: number[], responses?: number, repeat?: boolean) => any;
shuflle: (collection: any[]) => any[];
probs: (collection: any[]) => any[];

Basic (min,max,inclusive=false)

Retorna um número entre min e max.

min (número): número mínimo

max (número): número máximo

inclusive (bool, default=false): define se inclui o número máximo no sorteio, se true, retorna um número entre min e max, incluindo o máximo.

rand.basic(1,10) // Pode retornar um número inteiro de 1 a 9. Nunca retornará 10.
rand.basic(1,10,true) // Pode retornar um número inteiro de um a dez. Pode retornar 10.

Choice (collection,t=1,repeat=true)

Retorna um item (ou mais) sorteado de uma coleção.

collection (list): fonte de dados a ser sorteada.

t (número, default=1): define quantos resultados serão retornados, ou seja, quantos sorteios serão feitos.

repeat (bool,default=true): define se os itens sorteados poderão ser repetidos no resultado, caso t > 1.

let lista = ['maçã','banana','melancia','batata','tomate']

rand.choice(lista), // Pode retornar : 'batata'
rand.choice(lista,3), // Pode retornar: ['tomate','banana','tomate']
rand.choice(lista,3,false) // Pode retornar: ['tomate','banana','melancia'] Nunca retonará o array acima.

Se t > 1, uma lista é retornada, com os múltiplos resultados. Se não, um item da coleção é retornado.

t não pode ser maior do que collection.length, se repeat = false.

Choices (collection,weight,t=1,repeat=true)

Retorna um item (ou mais) sorteado de uma coleção. Baseado nas probabilidades passadas.

collection (list): fonte de dados a ser sorteada.

weight (list): Uma lista de números, que representa as chances de cada item ser sorteado respectivamente.

t (número, default=1): define quantos resultados serão retornados, ou seja, quantos sorteios serão feitos.

repeat (bool,default=true): define se os itens sorteados poderão ser repetidos no resultado, caso t > 1.


let lista = ['Carro','Avião','Barco']

rand.choices(lista,[1,2,1])//'Avião tem 2x mais chances de ser escolhido.'

Se t > 1, uma lista é retornada, com os múltiplos resultados. Se não, um item da coleção é retornado. O t não pode ser maior do que collection.length, se repeat = false. _Weight deve ter o mesmo tamanho da coleção.

Probs (collection)

Retorna a chance (em um número decimal) de cada elemento de uma coleção ser sorteado. Analisando repetições.

collection (list): Uma lista a ser analisada.


let lista = ['Carro','Avião','Avião','Barco']

rand.probs(lista)//Retorna uma lista de listas, com o item e sua chance de ser sorteado: [["Avião", 0.5]["Carro", 0.25]["Barco", 0.25]]

Shuflle (collection)

Embaralha uma lista. Muda a posição dos elementos aleatoriamente.

collection (lista): Lista a ser embaralhada.

let lista = ['maçã','banana','melancia','batata','tomate','Carro','Avião','Avião','Barco']


rand.shuflle(lista) // Pode retornar ["batata", "Carro", "Avião", "maçã", "banana", "Avião", "melancia", "Barco", "tomate"]

Fique à vontade em colaborar com sugestões ou correção de erros. ;)