WeChat red packet 5 yuan random red packet random amounts

WeChat red packet random number_WeChat random red packet number details and algorithm code

1 Requirements

Write? a fixed red envelope + random red envelope

Fixed red envelope is each red envelope? The amount of each red packet is the same as the amount of each red packet. The number of fixed red envelopes is as many as there are? The amount is the same as the number of fixed red envelopes.

The need for random red packets is. If the total red envelope? amount of 5 dollars, need to send 10 red envelopes. Random range is 0.01 to 0.99; 5 yuan must be sent out, ? The amount needs to be normally distributed with a ? normal distribution with a definite trend.

(0.99 can be specified arbitrarily, can also be avg * 2 - 0.01;? e.g. avg = 5 / 10 = 0.5; (avg * 2 - 0.01 = 0.99))

2 Requirements Analysis

2.1 Fixed Bonus Packets

If it is a fixed bonus packet, the algorithm is ? A straight line. t is the amount of the fixed bonus. As in the figure.

f(x) = t;(1 <= x <= num)

image.png

2.2 Random Red Envelope

If we make ? random function rand. rand(0.01,0.99); then 10 times randomly, if the worst case are ? amount 0.99, the total ? amount is $9.9. It will be more than $5. The amount would also not be normally distributed. Finally, I've been thinking about how to use the math function as a randomizer. I thought about using a mathematical function as a random red packet generator, which could be used to generate a random red packet. You can use a parabola, a triple function, and a randomizer. Parabolas, trigonometric functions. The parabola, the trigonometric function. Finally, the isosceles triple function was chosen. Linear function.

1 Principle of the algorithm

If you need to send a red envelope total? Amount is totalMoney, the number of red envelopes is num,? The range of the amount is [min,max], linear? The program is shown in the figure.

image.png

Coordinates of the three points:

(x1,y1) = (1,min)

(x2,y2) = (num/2,max)

(x3,y3) = (num,min)

Determined linear? Program:

$y = 1.0 * ($x - $x1) / ($x2 - $x1) * ($y2 - $y1) + $y1 ; (x1 <= x <= x2)

$y = 1.0 * ($x - $x2) / ($x3 - $x2) * ($y3 - $y2) + $y2; (x2 <= x <= x3)

Fix the data:

y(Hop) = y1 + y2 + y3 + ...... ynum;

y(together) has the possibility > totalMoney , indicating ? into? amount more, need to fix the data, then from (y1,y2,y3 .... .ynum) these each time to reduce 0.01. Until y(together) = totalMoney.

y(together) has the possibility < totalMoney , that means ? The amount is less than the total amount. amount is less, need to fix the data, then from (y1,y2,y3.... .ynum) these each time plus 0.01. until y (together) = totalMoney.

2 Sample Algorithm Principles

If you need to send a red packet with a total amount of 11,470, the red packet will be sent to the person who has the right to send the red packet to the person who has the right to send the red packet. amount is 11470, the number of red envelopes is 7400, the ? The range of the amount is [0.01,3.09], the linear? The program is shown in the figure.

image.png

3 Requirements Design

3.1 Class Diagram Design

image.png

3.2 Source Code Design

/**

* Random Red Envelope+Fixed Red Envelope Algorithm [Strategy Mode]

*

// Configuration Transmission Data DTO

class OptionDTO

{

// Total Red Packet? Amount

public $totalMoney;

// Number of red packets

public $num;

// Range start

public $rangeStart;

// Range settlement

public $rangeEnd ;

//? Randomized Red Packet Residuals

public $builderStrategy;

/// Randomized Red Packet Residuals

public $randFormatType; //Can_Left: don't fix the data, there can be residuals; No_Left: can't have residualspublic static function create($totalMoney,$num,$rangeStart,$rangEnd, $builderStrategy,$randFormatType = 'No_Left')

{

$self = new self();

$self->num = $num;

$self->rangeStart = $rangeStart;

$self->rangeEnd = $rangEnd;

$self->totalMoney = $ totalMoney;

$self->builderStrategy = $builderStrategy;

$self->randFormatType = $randFormatType;

return $self;

}

}

// Red Packet? The generator picks up?

interface IBuilderStrategy

{

//Creating a Red Packet

public function create();

//Setting the configuration

public function setOption( OptionDTO $option);

// Is it possible? into a red packet

public function isCanBuilder();

//? into a red packet function

public function fx($x);

}

// Fixed EqualPackageStrategy

class EqualPackageStrategy implements IBuilderStrategy {

// Individual Red Packets ? Amount

public $oneMoney;

//Quantity

public $num;

public function __construct($option = null)

{

if($option instanceof OptionDTO)

{

$this->setOption($option);

}

}

public function setOption(OptionDTO $option)

{

$this->oneMoney = $option->rangeStart;

$this->num = $option->num;

}

public function create()< /p>

{

$data = array();

if(false == $this->isCanBuilder())

{

return $data;

}

$data = array();

$this->num = $option->num;

public function create()<)

if(false == is_int($this->num) || $this->num <= 0) {

return $data;

}

for($i = 1;$i <= $this->num;$i++)

{

$data[$i] = $this->fx($i);

}

return $data;

}

/**

*The equal bonus? program is? a straight line

*

* @param mixed $x

* @access public

* @return void

*/

public function fx($x)

{

return $ this->oneMoney;

}

/**

* Whether or not the red envelope can be fixed

*

* @access public

* @return void

*/

public function isCanBuilder()

{

if(false == is_int($this->num) || $this->num <= 0)

{

return false;

}

if( false == is_numeric($this->oneMoney) || $this->oneMoney <= 0)

{

return false;

}

// Individual bonus? less than 1 cent

if($this->oneMoney < 0.01)

{

return false;

}

return true;

}

}

// Randomized red packet strategy (three? Shape)

class RandTrianglePackageStrategy implements IBuilderStrategy

{

//Total

public $totalMoney;

//Quantity of red packets

public $num;

// Random red packet most? value

public $minMoney;

/// Random red packet most? value

public $maxMoney;

// Fix data? Format: NO_LEFT: red packet total = budget total; CAN_LEFT: red packet total <= budget total public $formatType;

//Budget remaining? Amount

public $leftMoney;

public function __construct($option = null)

{

if($option instanceof OptionDTO)

{

{

$this->setOption($option);

}

}

public function setOption(OptionDTO $option) {

$this->totalMoney = $option ->totalMoney;

$this->num = $option->num;

$this->formatType = $option->randFormatType; $this->minMoney = $ option->rangeStart;

$this->maxMoney = $option->rangeEnd;

$this->leftMoney = $this->totalMoney;

}

< p>/**

* Create a random red packet

*

* @access public

* @return void

*/

public function create()

{

$data = array();

if(false == $this->isCanBuilder())

{

return $data;

}

$leftMoney = $this->leftMoney;

for($i = 1;$i <= $this->num;$i++)

{

$data[$i] = $this->fx($i);

$leftMoney = $leftMoney - $data[$i];

}

list($okLeftMoney,$okData) = $this->format($leftMoney,$data);

shuffle($okData);

$this-> leftMoney = $okLeftMoney;

return $okData;

}

/**

* Whether or not it is possible to send out random red envelopes

* @access public

* @return void

*/

public function isCanBuilder()

{

if(false == is_int($this->num) || $this->num <= 0)

{

return false;

}

if(false == is_numeric($this->totalMoney) || $this->totalMoney <= 0) {

return false;

}

//mean

$avgMoney = $this->totalMoney / 1.0 / $this->num;

if($avgMoney < $this->minMoney )

{

return false;

}

return true;

}

* Get remaining ? Amount

* @access public

public function getLeftMoney()

{

return $this->leftMoney;

}

/**

* Random bonus? into a function. Three? function. [(1,0.01),($num/2,$avgMoney),($num,0.01)] * @param mixed $x,1 <= $x <= $this->num;

* @access public

* @return void

*/

public function fx($x)

{

if(false == $this->isCanBuilder())

{

return 0;

}

if($x < 1 || $ x > $this->num)

{

return 0;

}

$x1 = 1;

$y1 = $this->minMoney;

//middle point

$x2 = ceil($this-> ;num / 1.0 / 2);

//my peak

$y2 = $this->maxMoney;

//final point

$x3 = $this->num;

$y3 = $this->minMoney;

// //When x1,x2,x3 are all 1's (vertical lines)

if($x1 == $x2 && $x2 == $x3)

{

// '/_\' three? shape of the linear? program

//'/' part

if($x1 ! = $x2 && $x >= $x1 && $x <= $x2)

{

, $y = 1.0 * ($x - $x1) / ($x2 - $x1) * ($y2 - $y1) + $y1; return number_format($y, 2, '.' , '');

}

//'\' shape

if($x2 ! = $x3 && $x >= $x2 && $x <= $x3)

{

$y = 1.0 * ($x - $x2) / ($x3 - $x2) * ($y3 - $y2) + $y2; return number_format($y, 2, '.'. , '');

}

return 0;

}

/**

* Formatting Red Packet Fixing Data

*

* @param mixed $leftMoney

* @param array $data

* @access public

* @return void

*/

private function format($leftMoney,array $data)

{

// Can't send a random red packet

if( false == $this->isCanBuilder())

{

return array($leftMoney,$data);

}

// Red envelope remainder is 0

if(0 == $leftMoney) //? Need to fix data

return array($leftMoney,$data);

}

// Array is empty

if(count($data) < 1)

{

return array($leftMoney,$ data);

}

//If it's Can_Left and $leftMoney > 0

if('Can_Left' == $this->formatType

&& $leftMoney > 0)

// If there is still money left, try adding to ? one. while($leftMoney > 0)

{

$found = 0;

foreach($data as $key => $val)

{

// Reduce loop optimization

if($leftMoney < ;= 0)

{

break;

}

//prejudice

$afterLeftMoney = (double)$leftMoney - 0.01;

$afterVal = (double)$val + 0.01;

if( $afterLeftMoney >= 0 && $afterVal <= $this->maxMoney)

{

$found = 1;

$data[$key] = number_format($ afterVal,2,'.' If the red envelopes have all been the most? value. This is when a flag must be given at the time of splitting to prevent ? dead loop. if($found == 0)

{

break;

}

}

//// If $leftMoney < 0 , it means that ? is over budget and needs to be reduced by a portion of the red envelope?

while($leftMoney < 0)

{

$found = 0;

foreach($data as $key => $val)

{

If($leftMoney >= 0)

If($leftMoney >= 0)

< p>{

break;

}

//prejudice

$afterLeftMoney = (double)$leftMoney + 0.01;

$afterVal = (double)$val - 0.01;

if( $ afterLeftMoney <= 0 && $afterVal >= $this->minMoney)

{

$found = 1;

$data[$key] = number_format($afterVal, 2,'.' ,'');

$leftMoney = $afterLeftMoney;

$leftMoney = number_format($leftMoney,2,'. ,'');

}

}

}

// If ? None of the decreasing reds need to end, otherwise dead loop

if($found == 0)

{

}

}

return array($leftMoney,$data);

}

}

/Maintaining the Environment class for the strategy

class RedPackageBuilder

{

// Instance

protected static $_instance = null;

/**

* Singleton instance(get ? instance)

*

* @return MemcacheOperate

*/

public static function getInstance()

{

if (null === self::$_ instance)

{

self::$_instance = new self();

}

return self::$_instance;

}

/**

* The get strategy makes ? Reflection

*

* @param string $type type

* @return void

*/

public function getBuilderStrategy($type) {

$class = $ type.'PackageStrategy';

if(class_exists($class))

return new $class();

}

else

{

throw new Exception ("{$class} class does not exist!") )

}

}

public function getRedPackageByDTO(OptionDTO $optionDTO)

{

// Get Strategy

$builderStrategy = $this-& gt;getBuilderStrategy($optionDTO->builderStrategy); //set parameters

$builderStrategy->setOption($optionDTO);

return $ builderStrategy->create();

}

}

class Client

{

public static function main($argv)

{

$dto = OptionDTO::create(1000,10,100,100,'Equal');

$data = RedPackageBuilder::getInstance()->getRedPackageByDTO($dto);

//print_r($data);

// Random RedPackage [fix data]

$dto = OptionDTO::create(5,10,0.01,0.99,'RandTriangle');

$data = RedPackageBuilder::getInstance()->getRedPackageByDTO($dto); print_r($data);

// Random RedPackage [no data fix]

$dto = OptionDTO::create(5,10 ,0.01,0.99,'RandTriangle','Can_Left');

$data = RedPackageBuilder::getInstance()->getRedPackageByDTO($dto);

//print_r( $data);

}

$

5.9

Baidu Wikipedia VIP Limited Time Offer Now Open, Enjoy 600 Million+ VIP Contents

Get it Now

WeChat Random Numbers Wechat random number of red envelopes and algorithmic code

WeChat random numbers wechat random numbers wechat red envelope Detailed explanation and algorithm code

1 Requirements

Write? A fixed red packet + a random red packet

A fixed red packet is each red packet? The amount of each red packet is the same as the amount of each red packet. The number of fixed red envelopes is as many as there are? The amount is the same as the number of fixed red envelopes.

The need for random red packets is. If the total red envelope? amount of 5 dollars, need to send 10 red envelopes. Random range is 0.01 to 0.99; 5 yuan must be sent out, ? The amount needs to be normally distributed with a ? normal distribution with a definite trend.

(0.99 can be specified arbitrarily, can also be avg * 2 - 0.01;? e.g. avg = 5 / 10 = 0.5; (avg * 2 - 0.01 = 0.99))

Page 1

2 Requirements Analysis

2.1 Fixed Bonus Packets

If it is a fixed bonus packet, the algorithm is ? A straight line. t is the amount of fixed bonus. As in the figure.

f(x) = t;(1 <= x <= num)

image.png

2.2 Random Red Envelope

If we make ? random function rand. rand(0.01,0.99); then 10 times randomly, if the worst case are ? amount 0.99, the total ? amount is $9.9. It will be more than $5. The amount would also not be normally distributed. Finally, I've been thinking about how to use the math function as a randomizer. I thought about using a mathematical function as a random red packet generator, which could be used to generate a random red packet. You can use a math function as a randomizer. Parabolas, trigonometric functions. The parabola, the trigonometric function. The final choice was the isosceles triple? Linear function.

Page 2

1 Principle of the algorithm

If you need to send red envelopes total? Amount is totalMoney, the number of red envelopes is num, ? The range of the amount is [min,max], the linear? The program is shown in the figure.

image.png

Coordinates of the three points:

(x1,y1) = (1,min)

(x2,y2) = (num/2,max)

(x3,y3) = (num,min)

Determined linear? Program:

$y = 1.0 * ($x - $x1) / ($x2 - $x1) * ($y2 - $y1) + $y1 ; (x1 <= x <= x2)

Page 3

$y = 1.0 * ($x - $x2) / ($x3 - $x2) * ($y3 - $y2) + $y2; (x2 <. = x < = x3)

Fixing the data:

y(Hop) = y1 + y2 + y3 + ...... ynum;

y(combined) has the possibility > totalMoney , indicating ? into? amount more, need to fix the data, then from (y1,y2,y3 .... .ynum) these each time to reduce 0.01. Until y(together) = totalMoney.

y(together) has the possibility < totalMoney , that means ? The amount is less than the total amount. amount is less, need to fix the data, then from (y1,y2,y3.... . ynum) these each time plus 0.01. Until y (together) = totalMoney.

Page 4

2 Sample Algorithmic Principles

If you need to send a red packet with a total amount of 11,470, the red packet will be sent to a person who is not a member of the family, and the amount of the red packet is 11,470. amount is 11470, the number of red envelopes is 7400, the ? Amount range is [0.01,3.09], linear? The program is shown in the figure.

image.png

3 Requirements Design

3.1 Class Diagram Design

image.png

3.2 Source Code Design

//**

* Random Red Envelope+Fixed Red Envelope Algorithm [Strategy Mode]

Page 5

*/

//Configure the transmission data DTO

class OptionDTO

{

///Total red packet? Amount

public $totalMoney;

// Number of red packets

public $num;

// Range start

public $rangeStart;

Page 6

// Range settlement

public $rangeEnd;

//? into bonus strategy

public $builderStrategy;

/// Random bonus remainder rules

public $randFormatType; //Can_Left: no data fixing, there can be a remainder; No_Left: there can be no remainder public static function create($totalMoney,$num,$rangeStart,$rangEnd, $builderStrategy,$randFormatType = 'No_Left')

Page 7

{

$self = new self();

$self->num = $num;

$self->rangeStart = $rangeStart;

$self->rangeEnd = $rangEnd;

$self->. totalMoney = $totalMoney;

$self->builderStrategy = $builderStrategy;

$self->randFormatType = $randFormatType;

return $self;

Expand the full text?

Read the full text for free in the App

Go to the Wenku App and sign in to receive a smooth reading card to read the random numbers of the WeChat Red Packet for free... Full text

Limited free

Long guide

Transfer to the net disk

Send to WeChat

Download the document

Beijing Baidu Netcom Technology Co. Version No. 8.0.70 Privacy Policy Privileges

Copyright: This document is provided by the user and uploaded by the revenue exclusively belongs to the provider of the content, if content There is infringement, please report or claim

Page 8

Selected WeChat Red Packet Random Numbers for ... Member Documents 964 articles

WeChat Red Envelope Random Amount Generation Algorithm Simulation and Application

2,537 readers

WeChat Red Envelope Random Amount Generation Algorithm Simulation and Application

1,455 readers

WeChat Red Envelope Amount Really Randomly Assigned?

2391 readers

WeChat Red Envelope Algorithm Analysis and Implementation

2508 readers

Get All Documents4326 people are looking at it

Based on your browsing to organize a collection of information for you

WeChat Red Envelope Random Numbers_WeChat Random Red Envelope Numbers Detailed and Algorithm Code

Folder

WeChat red packet law analysis - Baidu library

3.6 points

2906 reads

Popularity good article

Five five packets how to guess the end of the red packet - Baidu library

4.4 points

1,082 reads

WeChat red packet random amount of algorithms to generate Simulation and Application - Baidu Wencu

4.0 points

1491 reads

Recent downloads have soared

Remaining 10 selected documents

Go to APP to get the whole collection in one click

Related Documents

WeChat Red Envelope Random Amounts Generation Algorithm Simulation and Application

Free Access to Full Text

WeChat Red Envelope Random Amount Generation Algorithm Simulation and Application

Free Access to Full Text

WeChat Red Envelope Amounts Are Really Randomly Assigned?

Get Full Text for Free

WeChat Red Envelope Algorithm Analysis and Implementation

Get Full Text for Free

WeChat Sending Red Envelope Numbers Meaning of the Book of Classes.doc

2,567 people have read

Industry Favorite

Microcomputer Systems Microprocessor Principles and Applications Test Banks and Answers (Editable)

2060 people have read

Thousand Miles

Computer Network System Tender (Technical Part)

1569 people have read

Network Security Equipment-Net Gate [Collated]

1108 people have read

Four Ways to Export Excel Data by ASP

2213 people have read

Schools to carry out network safety education activities program

1822 people have read

Title 3 Comprehensive Application Comprehensive Case 5 Comprehensive Case of Computer Network Application

2470 people have read

How to Solder the CPU Pin Broken

1218 people have read

Data Structures Sequential Table Lookup Insertion and Deletion

1594 people have read it

Network Security Construction Implementation Program

1331 people have read it

Network Security Inspection Self-Inspection Form

1489 people have read it

See More

Recommended Documents Collection