• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Backend DRAWING WITHOUT REPEATS IN PHP AND C++. THE MILLIONAIRES GAME

Status
Not open for further replies.

avolfer

Member
User
Joined
Feb 20, 2023
Messages
5
Reputation
0
Reaction score
0
Points
1
Credits
0
‎2 Years of Service‎
100%
This is a common question: how to randomize values from a certain set (an array of values) in such a way that none of them are repeated? Today I present the implementation of such an algorithm in PHP and C++. There will also be a bonus in the form of a mini-game written in PHP. Here is the no-repeat randomization algorithm in PHP:

To see this hidden content, you must like this content.
As a result of executing the code, we get an array named $random[] containing 5 unique question numbers (here in indexes from 1 to 5). The key moment of the algorithm is checking each time whether the question number just drawn from the range is not already in the table $drawn[]. If so, the $draw_ok variable is false, which means that the drawn number will not be written to the table a second time. And thanks to the outer do..while loop, there will be another attempt to randomly select a unique number. The same is true in C++. I have prepared two ZIP packages for download, containing in addition to the algorithm a mini demo version (to be able to see the results of the algorithm on the screen).

 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top