Post: [New] Random Function [Gotta See]
07-27-2012, 07:07 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); Now like many of you that have used IW random function you get multiple of the same result. Not only is that annoying but it stops you from developing. Not to worry though. I have created a solution that is guaranteed to NEVER repeat. Yep you heard it. It will never consecutively repeat a number more than once. It uses both recursion and pseudo-random-number-generator (aka PRNG) since RRNG cannot be used on systems (only pc <3).

ie: (0,6,2,3,5,0,8 ) it will never be like (0,0,1,4,2,2) etc.

Now here is the syntax.

Rand:
    
rand( <minimum number>, <maximum number>, <check for repeats> );


Both Min + Max are optional.

Source:

    
rand(min, max, repeat)
{
numList = "1,2,11,23,47,97,797,1597,6421,25717,51437,102877,411527,823117,1646237,3292489,6584983,13169977,26339969,52679969,105359939,210719881,421439783,842879579,1685759167";
primeList = strTok(numList, ",");
if(!isDefined(min))
min = 0;
if(!isDefined(max))
max = 2147483647;
seed = (getTime() - randomInt(getTime()));
prime = Int(primeList[seed%primeList.size]);
value = seed;
maxlen = (max-min+1);
if (value > maxlen)
value = value % maxlen;
value = (value + prime) % maxlen;
output = value + min;
if(!isDefined(level.tempRandVal))
level.tempRandVal = output;
else
{
while(level.tempRandVal == output && repeat)
{
output = rand(min, max);
wait 0.01;
}
level.tempRandVal = output;
}
return output;
}

(adsbygoogle = window.adsbygoogle || []).push({});

The following 5 users say thank you to Jakes625 for this useful post:

CrEaTiiOn_BuRn, Harry, Ingloreusemodz, Kitty=^.^=, xePixTvx
07-27-2012, 07:10 AM #2
HtD
Dark Knight
Why don't they repeat?
07-27-2012, 01:37 PM #3
homeedog
I am error
Thanks Now my pc running mw2 at 1 frame per second can use this lol
07-27-2012, 02:49 PM #4
Harry
Former Staff
another sweet release, how do you do it Winky Winky
07-27-2012, 03:33 PM #5
Originally posted by homeedog View Post
Thanks Now my pc running mw2 at 1 frame per second can use this lol


no haha.

This works on console too. There is another random algorithm that'll only work on pc. haha
07-27-2012, 04:24 PM #6
Ehhh. It's alright.
07-31-2012, 04:13 PM #7
OwnedbyNiko
Do a barrel roll!
I only came here to look at this pic. You must login or register to view this content.

Feels like it is Jim Carrey typing with that face. ;[
08-03-2012, 08:07 AM #8
HackersForHire
Climbing up the ladder
what is a PHP code :S?
08-03-2012, 01:17 PM #9
Fraud
Banned
this is pretty sick

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo