Results 1 to 10 of 32
-
2nd Jul 2010, 06:13 PM #1OPRespected DeveloperWebsite's:
wrzc.org[PHP] Random Number Problem
Basically I want to generate a Random number but increase the chances of lower numbers appearing more.
if I just use mt_rand(1, 1000) the chances of getting the number 1 is the same as 468 which is the same as 1000.
I want to increase the chances of lower numbers appearing.
This poor way shows what I mean
PHP Code:if (mt_rand(1, 2) == 1) // 50-50 chance
{
mt_rand(1, 10);
}
else if (mt_rand(1, 2) == 1)
{
mt_rand(10, 100);
}
else
{
mt_rand(100, 1000);
}
It's still pretty crap though as the chance of getting 124 is the same as 975 (not to mention it's generating upto 5 times to get one result).
I want a gradual increase in chance. I don't even know the mathematical term. Searching "php random sliding scale" gives random image scripts and "php random heavy slide" gives articles on the difference between rand() and mt_rand()
Can anyone help with an fast efficient function or even tell me the mathematical term for what I want to make searching easier?Mr Happy Reviewed by Mr Happy on . [PHP] Random Number Problem Basically I want to generate a Random number but increase the chances of lower numbers appearing more. if I just use mt_rand(1, 1000) the chances of getting the number 1 is the same as 468 which is the same as 1000. I want to increase the chances of lower numbers appearing. This poor way shows what I mean if (mt_rand(1, 2) == 1) // 50-50 chance { Rating: 5Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic
Huge list of Warez Sites and free Multiposter Templates
-
2nd Jul 2010, 06:18 PM #2ლ(ಠ益ಠლ)Website's:
extremecoderz.comhmmm. i have an idea.
lemme have a go.
-
2nd Jul 2010, 06:20 PM #3Respected DeveloperPHP Code:
$num = (time() & 1) ? mt_rand(1, 10) : mt_rand(1, 1000);
PHP Code:$num = (time() & 1) ? mt_rand(1, 10) : mt_rand(1, mt_rand(10, 1000));
-
2nd Jul 2010, 06:27 PM #4ლ(ಠ益ಠლ)Website's:
extremecoderz.coma bit more complicated, but you get the idea. Sorry, i dont know php, but you can of course see the logic.
PHP Code:static void DoWork()
{
Random rnd = new Random(5000);
string output = string.Empty;
int num1 = rnd.Next();
int num2 = num1;
num1 = rnd.Next();
if (num1 > num2)
{
for (int i = 0; i < 5; i++) // 5 chances to be smaller than previous.
{
num1 = rnd.Next();
if (num1 < num2)
break;
}
}
output += num1.ToString() + Environment.NewLine;
}
-
2nd Jul 2010, 06:28 PM #5MemberWebsite's:
litewarez.net litewarez.com triniwarez.comPHP Code:if(substr(time(),0,-1) > 7)
{
//LOWER NUMBER (Chances are 7/10) of being lower
}else
{
//Higher
}
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
2nd Jul 2010, 06:29 PM #6ლ(ಠ益ಠლ)Website's:
extremecoderz.comwhy am i the only one writing the whole thing
makes me look bloated
-
2nd Jul 2010, 06:33 PM #7MemberWebsite's:
litewarez.net litewarez.com triniwarez.comPHP Code:function doWork()
{
$rnd = rand(0,5000);
$num1 = $num2 = $rnd+1;
if(($num1+1) > $num2)
{
for($i=0;$i<5;$i++)
{
$num1 = $rnd+1;
}
}
return $num1;
}
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
2nd Jul 2010, 06:44 PM #8Respected Developer
-
2nd Jul 2010, 06:44 PM #9OPRespected DeveloperWebsite's:
wrzc.orgOk so these are all far superior on what I used as an example but their's no way of doing this so
1 is bigger than 2 which is bigger than 3 which is bigger than 4 which is bigger than 5 .....
I asked a friend (Phd Mathematical Student) after making this topic and said I need to set up a matrix and add a curve or something where x=0 and y=1000 where points were picked but I didn't really understand what he was saying.
Anyway it's not that important as long as it's roughly weighted which we've all got. Just though their was a maths way. Maths is seriously not my strong point.
See while Hyperz way is fast the chances of getting 116 are the same as 959 which isn't exactly what I want.
Thanks for all the quick replies.Tutorial How to SEO your Warez Site a guide to help you increase your organic traffic
Huge list of Warez Sites and free Multiposter Templates
-
2nd Jul 2010, 06:52 PM #10Respected Developer
Oh I didn't think of a matrix, that would actually make it fairly effective and also easy to implement. I'll write another example with once I finish my coffee.
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Problem with number of posts at homepage
By bdr111446 in forum WordpressReplies: 0Last Post: 21st May 2012, 03:10 PM -
Problem on DLE 9.3 Error Number: 1267
By Devils in forum Technical Help Desk SupportReplies: 6Last Post: 26th Sep 2011, 04:17 PM -
From random to more random
By dannym23 in forum General DiscussionReplies: 4Last Post: 13th Aug 2011, 07:35 PM -
DLE random log out problem
By seraphim in forum Webmaster DiscussionReplies: 0Last Post: 12th May 2011, 01:36 PM -
How to get those random ads?
By DXS in forum Webmasters, Money MakingReplies: 3Last Post: 8th Mar 2009, 08:13 AM
themaLeecher - leech and manage...
Version 5.03 released. Open older version (or...