Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-23-2013, 12:35 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
Algorithm RNG that progressively gets harder the higher the number

I currently need a way to create random number generation that gets progressively harder the higher the number..

example:
You have the chance of getting a number 0-10.

You are most likely to get 1, less likely to get 2, even less likely to get 3 and so on.

Does anyone have any suggestions on how to do where it would be progressively harder each number you go up or would my best bet be to do a bunch of logic checks to see if a random number is within a set range and iteration lessen the the gap that allows it to proceed to the next iteration until I've hit the whatever the max number?
Reply With Quote
  #2  
Old 08-23-2013, 03:15 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Sounds a bit like "normal distribution", or "the bell curve." You can generate numbers that act like that using the "Box–Muller transform." Look up these things.

My attempt at implementing it in GScript:
PHP Code:
function normal() {
  
temp.2.7182818284590452353602874713526624977572470936999;
  return 
cos(2*pi*random(01)) * (-log(temp.erandom(01)))^0.5;

It generates numbers that are more likely to be close to 0.

If you know in advance that you only need numbers 1 through 10 it's probably easier to do it another way.
__________________
Testbed user: I figured since I can never find any scripters it was time to take desperate measures...and...TEACH MYSELF 0.0
Reply With Quote
  #3  
Old 08-23-2013, 04:03 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by DrakilorP2P View Post
Sounds a bit like "normal distribution", or "the bell curve." You can generate numbers that act like that using the "Box–Muller transform." Look up these things.
This is what we did on Kingdoms for the mystery boxes (for determining which item you got). If you need more code samples, I can dig up our implementation as well.
__________________
Reply With Quote
  #4  
Old 08-23-2013, 04:14 PM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
I'll take a look at it when I get home and see if I can get a general understanding on what he provided and if not I'll take you up on that probably.
Reply With Quote
  #5  
Old 09-01-2013, 03:03 AM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
wow i'm bad with statistics. apparently you can transform your rand()'s uniform distribution into a desired distribution via the latter's quantile function which is the inverse of the cumulative distribution function which is the integral of the probability density function and you could pick something like 2*(1-x) as your density function (for 0<=x<1, i guess the idea is that it's normalized). then wolfram alpha gives 1-sqrt(1-x) (the + solution sounds useless i dunno). so you'd transform the uniform 0<=x<1 rand() into a number between 0 and 10 by doing (1-sqrt(1-rand()))*11 and rounding down.

i guess if 1-x doesn't appeal to you as a distribution you can do the whole thing with stuff like 1-sqrt(x) and 1-x*x and that sort of thing and see if something cool happens but wow i hate statistics.
Reply With Quote
  #6  
Old 09-01-2013, 11:00 AM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
Send a message via AIM to Crono
Quote:
Originally Posted by Loriel View Post
wow i'm bad with statistics. apparently you can transform your rand()'s uniform distribution into a desired distribution via the latter's quantile function which is the inverse of the cumulative distribution function which is the integral of the probability density function and you could pick something like 2*(1-x) as your density function (for 0<=x<1, i guess the idea is that it's normalized).
wat
__________________
Reply With Quote
  #7  
Old 09-01-2013, 01:02 PM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
Good seeing you as usual Loriel.
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #8  
Old 09-02-2013, 02:36 AM
dylan dylan is offline
AGT
Join Date: Jul 2012
Location: United States
Posts: 60
dylan has a spectacular aura about
I was trying to do something to where the chance exponentially gets higher or lower, but it seems the Math.pow(int, int) function no longer is in working fashion.
__________________

<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"
Reply With Quote
  #9  
Old 09-02-2013, 03:18 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
going off loriel's post... I came up with:

PHP Code:
function onCreated() {
  
temp.tmax 10;
  
temp.rand = function (m) { return int(((1-random(0,1)^0.5)) * m) };
  
  for (
temp.0temp.1000temp.i++) {
    
temp.("count_" temp.rand(temp.tmax))++;
  }
  for (
temp.0temp.temp.tmaxtemp.i++) {
    echo(
temp.i SPC temp.("count_" temp.i));
  }
}

/*
Sample:
0 179
1 170
2 145
3 126
4 115
5 95
6 75
7 59
8 27
9 9
*/ 
one other way I tried:

PHP Code:
function onCreated() {
  
temp.tmax 10;
  
temp.rand = function (m) {
    
temp.0;
    while (
random(0,1) > 0.5 && temp.m) {
      
temp.i++;
    }
    return 
temp.i;
  };
  
  for (
temp.0temp.1000temp.i++) {
    
temp.("count_" temp.rand(temp.tmax))++;
  }
  for (
temp.0temp.temp.tmaxtemp.i++) {
    echo(
temp.i SPC temp.("count_" temp.i));
  }
}

/*
Sample:
0 520
1 243
2 132
3 56
4 27
5 12
6 2
7 3
8 3
9 1
*/ 
I'm sure there's a math way to do it but **** it.
__________________
Quote:
Reply With Quote
  #10  
Old 09-02-2013, 03:23 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by dylan View Post
I was trying to do something to where the chance exponentially gets higher or lower, but it seems the Math.pow(int, int) function no longer is in working fashion.
You can simply use a caret in GScript—it's not used for xor like it is in most languages.
__________________
Reply With Quote
  #11  
Old 09-02-2013, 03:43 PM
scriptless scriptless is offline
Banned
Join Date: Dec 2008
Location: N-Pulse
Posts: 1,412
scriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to beholdscriptless is a splendid one to behold
This sounds interesting. Would defiantly make the daily freebies system more efficient. Is this also used in something like rarity of item spawns/drops?
Reply With Quote
  #12  
Old 09-02-2013, 04:30 PM
Loriel Loriel is offline
Somewhat rusty
Loriel's Avatar
Join Date: Mar 2001
Posts: 5,059
Loriel is a name known to allLoriel is a name known to allLoriel is a name known to allLoriel is a name known to all
Quote:
Originally Posted by fowlplay4 View Post
going off loriel's post... I came up with:

PHP Code:
(1-random(0,1)^0.5
It took me way too long to figure out why 1-sqrt(rand()) is the same thing as 1-sqrt(1-rand())
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:46 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.