Code Monkey home page Code Monkey logo

lottery's Introduction

lottery

一个经典抽奖概率算法实现

使用

  1. make 以默认配置及实例化名称实例化
// 抽奖配置
$settings = array(
    array("id" => 1, 'weight' => 10, 'score' => 1),
    array("id" => 2, 'weight' => 20, 'score' => 2),
    array("id" => 3, 'weight' => 30, 'score' => 3),
);
$result = Lottery::make()->go($settings);
  1. make 设置自定义配置选项并实例化 将开启内部调试输出工具,默认关闭
// 抽奖配置
$settings = array(
    array("id" => 1, 'weight' => 10, 'score' => 1),
    array("id" => 2, 'weight' => 20, 'score' => 2),
    array("id" => 3, 'weight' => 30, 'score' => 3),
);
$result = Lottery::make($config = array("debug" => true))->go($settings);
  1. make 设置实例名称并实例化
// 抽奖配置
$settings = array(
    array("id" => 1, 'weight' => 10, 'score' => 1),
    array("id" => 2, 'weight' => 20, 'score' => 2),
    array("id" => 3, 'weight' => 30, 'score' => 3),
);

$result = Lottery::make($name = "instance", $config = array("debug" => true))->go($settings);
  1. make 设置配置选项和实例名称并实例化
$settings = array(
    array("id" => 1, 'weight' => 10, 'score' => 1),
    array("id" => 2, 'weight' => 20, 'score' => 2),
    array("id" => 3, 'weight' => 30, 'score' => 3),
);

$result = Lottery::make($name = "instance", $config = array("debug" => true))->go($settings);

// 或

$result = Lottery::make($config = array("debug" => true), $name = "inatance")->go($settings);

配置选项

$config = array(
    "indexField" => 'pid',  // 抽奖配置中的主键字段,默认 id
    "weightField" => "weights", // 抽奖配置中的权重字段,默认 weight
    "debug" => true, //开启调试,默认关闭
);

方法

  1. 设置主键字段和权重字段
setFields($indexField = 'id', $weightField = 'weight') 
  1. 开启/关闭 调试
debug($boolean = true) 
  1. 执行抽奖
go($settings)

lottery's People

Contributors

huliuqing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.