Home php教程 PHP源码 php随机概率红包算法

php随机概率红包算法

May 23, 2016 am 08:39 AM


 /**
     * @param $num
     * @param $total
     * @param int $range  差距是否大
     * @return array|int
     */
    private function randomSplit($num,$total,$range=1){

        if($num<2){
            return $total;
        }

        $p=array();

        $min=floor($total/$num-$range);
        $max=floor($total/$num+$range);
        for($i=0;$i<$num-1;$i++){
            $depart=mt_rand($min,$max);
            $p[]=$depart;
            $total-=$depart;
        }
        $p[]=$total;
        return $p;

    }
Copy after login


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Quantile regression for time series probabilistic forecasting Quantile regression for time series probabilistic forecasting May 07, 2024 pm 05:04 PM

Do not change the meaning of the original content, fine-tune the content, rewrite the content, and do not continue. "Quantile regression meets this need, providing prediction intervals with quantified chances. It is a statistical technique used to model the relationship between a predictor variable and a response variable, especially when the conditional distribution of the response variable is of interest When. Unlike traditional regression methods, quantile regression focuses on estimating the conditional magnitude of the response variable rather than the conditional mean. "Figure (A): Quantile regression Quantile regression is an estimate. A modeling method for the linear relationship between a set of regressors X and the quantiles of the explained variables Y. The existing regression model is actually a method to study the relationship between the explained variable and the explanatory variable. They focus on the relationship between explanatory variables and explained variables

Generate random numbers and strings in JavaScript Generate random numbers and strings in JavaScript Sep 02, 2023 am 08:57 AM

The ability to generate random numbers or alphanumeric strings comes in handy in many situations. You can use it to spawn enemies or food at different locations in the game. You can also use it to suggest random passwords to users or create filenames to save files. I wrote a tutorial on how to generate random alphanumeric strings in PHP. I said at the beginning of this post that few events are truly random, and the same applies to random number or string generation. In this tutorial, I'll show you how to generate a pseudo-random alphanumeric string in JavaScript. Generating Random Numbers in JavaScript Let’s start by generating random numbers. The first method that comes to mind is Math.random(), which returns a float

The difference between random and pseudo-random The difference between random and pseudo-random Oct 10, 2023 am 09:27 AM

The difference between random and pseudo-random is predictability, reproducibility, uniformity and security. Detailed introduction: 1. Predictability. Random numbers cannot be predicted. Even if the past results are known, future results cannot be accurately predicted. Pseudo-random numbers can be predicted because they are generated by algorithms. As long as you know the algorithm and seed, you can regenerate the same sequence or sequence; 2. Reproducibility, random numbers are not reproducible, and the results generated each time are independent, while pseudo-random numbers are reproducible. Yes, just use the same algorithm and seeds etc.

How to use the random.randint() function to generate random integers in Python 2.x How to use the random.randint() function to generate random integers in Python 2.x Jul 31, 2023 pm 12:13 PM

Python is a popular programming language widely used in data analysis, machine learning, web development and other fields. In Python, the random module provides a random.randint() function for generating random integers. This article explains how to use the random.randint() function to generate random integers and provides some code examples. First, we need to import the random module: importrandom Next, we can call rando

A matrix probability problem? A matrix probability problem? Aug 28, 2023 pm 08:37 PM

Here we will see a matrix probability problem. We have a rectangular matrix. We can move in four directions from the current cell with equal probability. The four directions are left, right, up, and down. We want to calculate the probability after N moves starting from position M[i,j]. Here we are going to do some DFS related things. We will recursively traverse the four possible rooms starting from the current room. Then we calculate the probability of taking one less step. Since the four directions have equal probability, each direction will contribute 0.25 of the total probability. We will return 0 if a matrix boundary is crossed and 1 when N moves are completed. Let's look at the algorithm to get this idea. Algorithm matProb(m,n,x,y,N)Begin&nb

ups and downs numbers ups and downs numbers Aug 28, 2023 pm 01:41 PM

In this article, we will learn what a fluctuating number is and introduce our method of checking whether a given number is a fluctuating number, using a Boolean function to check for fluctuating numbers. Problem Statement We will be given a number and our task is to check if the given number is fluctuating. Let's first understand a fluctuating number; a fluctuating number is a number that consists of only two types of numbers, with every other number being the same. We can say that a fluctuating number is of the form "PQPQPQ" where P and Q are two different numbers in the number system. The first and second digits of a fluctuating number can never be the same, that is, 11111 is not a fluctuating number. We usually regard non-trivial fluctuating numbers as just fluctuating numbers, which means that the fluctuating numbers need to be composed of at least 3 digits

How to implement weighted random selection in Python? How to implement weighted random selection in Python? Sep 11, 2023 pm 09:45 PM

Python is a flexible and efficient programming language that provides a wide range of low-level functions and libraries to improve complex coding tasks. One of the tasks is to perform weighted irregular decision making, a measurable strategy where everything has a predefined probability of being picked. Unlike simple random selection, where each item has an equal chance of being selected, weighted random selection allows us to specify a probability of each item being selected, which may vary. This article aims to provide a comprehensive understanding of how to obtain weighted random selection in Python. Syntax The main method in Python that facilitates weighted random choices is random.choices(). This is its basic syntax: random.choices(popula

Python random module Python random module Sep 03, 2023 am 11:57 AM

In the world of programming, the ability to generate random values ​​is often crucial. Whether you are developing a game, simulation, statistical model, or simply need to introduce variability into your program, having a reliable and efficient way to generate random numbers is crucial. This is where the PythonRandom module comes in. The PythonRandom module provides a set of functions for generating random values, making it easy to introduce randomness into Python programs. From generating random numbers within a specific range to shuffling lists, simulating random events, and even generating random passwords, the Random module provides a wide range of functionality. In this blog post, we will explore the PythonRandom module in detail. We will learn how to generate random numbers, perform

See all articles