• Portal
  • Forums
  • Shop
  • Statistics
    • Players
      Games
      Maps
      Top
      Levels
      Countries
  • GameServer
  • Downloads
  • Discord
  • Logs
    • Chat
      Warns
      Bans
  • Search
  • Extras
    • Forum Members
      Team Members
      Stats For Nerds
      Recover Account
      Calendar
      Help
      Forum stats
      View New Posts
      View Today's Posts
Reign of the Undead - Revolution
Login to account Create an account
Login
Username:
Password: Lost Password?
 

Dear Guest!
Please sign up or login to use all features of the website.

  Reign of the Undead - Revolution Reign of the Undead Bugs
« Previous 1 ... 3 4 5 6 7 8 Next »
Pink ORB - MIxed

Thread Modes
Pink ORB - MIxed
Soldier . . . Offline
I am not a moderator
***
VIP
Donator
Insider
Posts: 222
Threads: 10
Joined: Jul 2012
Thanks given: 0
Thanks received: 90
#9
08-26-2016, 03:20 PM (This post was last modified: 08-26-2016, 03:21 PM by Soldier . . ..)
It is based on a Multiply With Carry generator and I added a extra, which makes the chance that the value is the same as the previous one, a lot smaller.
Do note that the constant and (sometimes) the start numbers can make or brake the randomness!

The variable iSize is the max value  - 1 it can select from.
So if iSize = 16, the return value will be between 0 and 15.

Made a little change: If both variable "m_z" and "m_w" become 0 at the same time. The output will always be 0. (something that we don't want Wink )

Code:
unsigned int random (unsigned int iSize)
{
    static unsigned int m_z = 12434;
    static unsigned int m_w = 33254;
    static unsigned int iRandOld = 0;
    
    m_z = 36969 * (m_z & 65535) + (m_z >> 16);
    m_w = 18000 * (m_w & 65535) + (m_w >> 16);
    
    if (iRandOld == (((m_z << 16) + m_w) % iSize))
    {
        m_z = 36969 * (m_z & 65535) + (m_z >> 16);
        m_w = 18000 * (m_w & 65535) + (m_w >> 16);
    }
    
    if ((m_z == 0) && (m_w == 0))
        {m_z = 12434;}
    
    iRandOld = ((m_z << 16) + m_w) % iSize;
    
    return (iRandOld);
}

note:
The variable "m_z", "m_w" and "iRandOld" need to be saved in a way that they wont get cleared.
(in 'c/c++' static enables you to save the declared variable outside the function)
Find
Reply
Thanks given by: fabio
Share Thread:    


Messages In This Thread
Pink ORB - MIxed - Forau - 08-23-2016, 07:59 PM
RE: Pink ORB - MIxed - Soldier . . . - 08-23-2016, 10:41 PM
RE: Pink ORB - MIxed - fashion - 08-23-2016, 11:35 PM
RE: Pink ORB - MIxed - fabio - 08-24-2016, 11:11 AM
RE: Pink ORB - MIxed - West - 08-24-2016, 03:38 PM
RE: Pink ORB - MIxed - Forau - 08-24-2016, 05:57 PM
RE: Pink ORB - MIxed - Soldier . . . - 08-24-2016, 09:02 PM
RE: Pink ORB - MIxed - fabio - 08-26-2016, 08:37 AM
RE: Pink ORB - MIxed - Soldier . . . - 08-26-2016, 03:20 PM
RE: Pink ORB - MIxed - fabio - 08-26-2016, 09:17 PM

  • View a Printable Version
  • Subscribe to this thread


Users browsing this thread:
1 Guest(s)

  • Contact Us
  • Forum team
  • Forum stats
  • Return to Top
 
  • RSS Syndication
  • Lite mode
  • Home
  • Help
 
© Copyright 2025 by MODS-Clan
www.modszombies.com



Linear Mode
Threaded Mode