A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 36

Thread: How random is random?

  1. #1
    SaphuA SaphuA's Avatar
    Join Date
    Oct 2002
    Location
    The Netherlands
    Posts
    2,180

    How random is random?

    Hey,
    I'm sure this has been asked before, and I'm almost sure there's something related to be found on the internet, but I'm not feeling like searching for it

    I was wondering, if you let Flash, or any other coding language, pick a random number; how the hell do they do that? I can't immagine that a programing language, can pick a random number by itself, so there must be something predefined. But if that's the case, then how random is random actualy? If it's predefined, then there's always something unnatural about it; which will make random not that random at all.

    Maybe a bit hard to explain, but I hope you're getting my point

    ~Sph

  2. #2
    - carly1979's Avatar
    Join Date
    May 2004
    Location
    down south, UK
    Posts
    1,778
    the word random bothers me. nothing is random- it is always chosen for some reason, no mater how obscure.

    i'm not really talking about programming, just general randomness.

  3. #3
    Member
    Join Date
    Nov 2004
    Location
    Singapore
    Posts
    90
    seems like it's not so random after all.....
    http://computer.howstuffworks.com/question697.htm

  4. #4
    Chaos silverx2's Avatar
    Join Date
    Jul 2002
    Location
    The hospital
    Posts
    1,262
    basicly when you tell teh computer to pick a random number you tell it to pick between 1 and x then depending on the cpu cycle it spits out a number, now adays its harder to predict what number will come up due to the cpu speeds being so insane but its not completely random, you would have to throw out a couple of random variables and a second random between 1 and x and then have to do a funy math formula to be even close to random.
    GhooooostGIrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrl
    https://signup.leagueoflegends.com?ref=4b5493e6c7342
    use the link above if you download league of legends.

  5. #5
    for the win Asclepeos's Avatar
    Join Date
    Dec 2000
    Posts
    388
    close enough to be random, then it might as well be. No need to fret about it, nothing profound will come out of it.

  6. #6
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    .......tada!
    -Aditya

  7. #7
    associate admedia's Avatar
    Join Date
    Oct 2001
    Location
    is
    Posts
    1,347
    In order to generate truly random numbers the seed should be an unpredictable value. (e.g. the current time in Timer)
    from...

  8. #8
    Sun Devil asun2art's Avatar
    Join Date
    Feb 2001
    Location
    Maui, Hawaii
    Posts
    572
    How do online poker sites produce random card shuffles, deals, flops?

    Joe?

  9. #9
    Information Architect Subway's Avatar
    Join Date
    Feb 2000
    Location
    Switzerland
    Posts
    4,779
    Click the "PSI" link in my footer.

    And have a look at the links I've posted over here: http://www.osxcode.com/2005/08/01/th...sness-project/

    Even quantum randomness is not really random.

    Fredi
    Mind Share Projects [ <- my latest projects ] [ my splash page -> ] Fredi Bach
    OS X Code (r,s) [ my Mac, web 2.0 and programming blog ]
    Not A Blog [ my personal weblog ]
    jMe Feed Aggregator [ my latest most famous project ]
    Web Command Line [ use the web like a real geek ]

  10. #10
    Always Twirling Toward Freedom pooon's Avatar
    Join Date
    Oct 2001
    Location
    On the sunny beaches of Canada
    Posts
    896
    You can create some sort of device that monitors a completely random natural event and sends its results to the computer. For example, you could place a piece of radioactive material in front of a Geiger counter and connect the Geiger counter to a computer. Since radioactive decay is random, the Geiger counter would create truly random numbers. This approach is pretty rare, because not many people have Geiger counters connected to their machine.

  11. #11
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    Quote Originally Posted by asun2art
    How do online poker sites produce random card shuffles, deals, flops?

    Joe?
    I'm not sure exactly. But, have you ever noticed that, when playing two tables at the same time, the VERY cards you need in one table are flopped on the other?!

  12. #12
    Sun Devil asun2art's Avatar
    Join Date
    Feb 2001
    Location
    Maui, Hawaii
    Posts
    572
    Quote Originally Posted by indivision
    I'm not sure exactly. But, have you ever noticed that, when playing two tables at the same time, the VERY cards you need in one table are flopped on the other?!
    I'll take it a step further, I've flopped a good hand on one window and raised on another thinking it was the first! THAT is pretty bad.

  13. #13
    Registered pseudo intellectual
    Join Date
    May 2005
    Location
    ol' Blighty
    Posts
    48
    For example, you could place a piece of radioactive material in front of a Geiger counter and connect the Geiger counter to a computer. Since radioactive decay is random, the Geiger counter would create truly random numbers. This approach is pretty rare, because not many people have Geiger counters connected to their machine.
    But even the time between emissions of a radioactive source arn't independent of one another, since the time would get exponentially larger over time.

    Although using levels of background radiation instead could be much more effective...

    For anyone interested, the following is a c# implementation of the Mersenne Twister random number generator. It is statistically one of the best algorithms for random number generation (in speed and 'randomness').

    most of the 'business' is done in genrand_int32()

    Code:
    using System;
    
    namespace Orthogonal.Common
    {
    	/// <summary>
    	/// Managed code implementation of the Mersenne Twister random number generator algorithm by
    	/// Makoto Matsumoto and Takuji Nishimura.
    	/// </summary>
    	/// <remarks>See <a href="http://www.math.keio.ac.jp/~matumoto/emt.html" target="_blank">
    	/// Mersenne Twister Home Page</a>.</remarks>. A good technical summary can be found on
    	/// John Savard's <a href="http://home.ecn.ab.ca/~jsavard/index.html" target="_blank">Mersenne Twister</a> page.
    	[CLSCompliant(false)]
    	public sealed class RandMT
    	{
    		const int N = 624;
    		const int M = 397;
    		const uint MATRIX_A = 0x9908b0dfU;		/* constant vector a */
    		const uint UPPER_MASK = 0x80000000U;	/* most significant w-r bits */
    		const uint LOWER_MASK = 0x7fffffffU;	/* least significant r bits */
    
    		static uint[] mt = new uint[N];			/* the array for the state vector  */
    		static uint mti = N+1;					/* mti==N+1 means mt[N] is not initialized */
    		static uint[] mag01 = { 0x0U, MATRIX_A };
    
    		//==========================================================================================
    		/// <summary>
    		/// Creates a random number generator seeded with the current time milliseconds.
    		/// </summary>
    		public RandMT()
    		{
    			init_genrand((uint)DateTime.Now.Millisecond);
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Creates a random number generator seeded with a specified integer.
    		/// </summary>
    		/// <param name="seed">The seed number for the generator.</param>
    		public RandMT(uint seed)
    		{
    			init_genrand(seed);
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Creates a rand number generator seeded with a specified integer array.
    		/// </summary>
    		/// <param name="seeds">The seed integer array for the generator.</param>
    		public RandMT(uint[] seeds)
    		{
    			init_by_array(seeds,(uint)seeds.Length);
    		}
    
    		#region Initializers
    		//==========================================================================================
    		/// <summary>
    		/// initializes mt[N] with a seed
    		/// </summary>
    		/// <param name="s"></param>
    		private void init_genrand(uint s)
    		{
    			mt[0] = s & 0xffffffffU;
    			for (mti=1; mti<N; mti++) 
    			{
    				mt[mti] = (1812433253U * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
     				/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
    				/* In the previous versions, MSBs of the seed affect   */
    				/* only MSBs of the array mt[].                        */
    				/* 2002/01/09 modified by Makoto Matsumoto             */
    				mt[mti] &= 0xffffffffU;
    				/* for >32 bit machines */
    			}
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// initialize by an array with array-length
    		/// init_key is the array for initializing keys
    		/// key_length is its length
    		/// slight change for C++, 2004/2/26
    		/// </summary>
    		private void init_by_array(uint[] init_key, uint key_length)
    		{
    			uint i, j, k;
    			init_genrand(19650218U);
    			i=1; j=0;
    			k = (N>key_length ? N : key_length);
    			for (; k!=0; k--)	//?? k>=0
    			{
    				mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525U)) + init_key[j] + j;	/* non linear */
    				mt[i] &= 0xffffffffU;		/* for WORDSIZE > 32 machines */
    				i++; j++;
    				if (i>=N)
    				{
    					mt[0] = mt[N-1];
    					i=1;
    				}
    				if (j>=key_length)
    					j=0;
    			}
    			for (k=N-1; k!=0; k--)	//?? k>=0
    			{
    				mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941U)) - i;		/* non linear */
    				mt[i] &= 0xffffffffU;		/* for WORDSIZE > 32 machines */
    				i++;
    				if (i>=N)
    				{
    					mt[0] = mt[N-1];
    					i=1;
    				}
    			}
    			mt[0] = 0x80000000U;		/* MSB is 1; assuring non-zero initial array */
    		}
    
    		#endregion
    
    		#region Standard Random Mockups
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random positive signed integer in the interval [0,0x7fffffff]. The value
    		/// is created by simply dropping the high-order sign bit of the raw unsigned value.
    		/// </summary>
    		/// <returns>A random positive signed integer in the interval [0,0x7fffffff].</returns>
    		public int Next()
    		{
    			return genrand_int31();
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random positive integer in the interval [0,maxValue). The value will be
    		/// GE zero and LT maxValue.
    		/// </summary>
    		/// <param name="maxValue">The maximum value ceiling.</param>
    		/// <returns>A random positive integer in the interval [0,maxValue).</returns>
    		public int Next(int maxValue)
    		{
    			return Next(0,maxValue);
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random positive integer in the interval [minValue,maxValue). The value will
    		/// be GE minValue and LT maxValue.
    		/// </summary>
    		/// <param name="minValue">The minimum value floor.</param>
    		/// <param name="maxValue">The maximum value ceiling.</param>
    		/// <returns>A random positive integer in the interval [minValue,maxValue).</returns>
    		/// <exception cref="ArgumentException">Thrown if the range is invalid.</exception>
    		public int Next(int minValue, int maxValue)
    		{
    			if (minValue >= maxValue)
    				throw new ArgumentException(string.Format("Next({0},{1}) sequence error",minValue,maxValue));
    			double d = (maxValue - minValue) * genrand_real2() + minValue;
    			return (int)d;
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random real number in the range [0,1). The value will be GE zero and LT 1.0.
    		/// </summary>
    		/// <returns>A random real number in the range [0,1).</returns>
    		public double NextDouble()
    		{
    			return genrand_real2();
    		}
    		#endregion
    
    		#region Original C Functions
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random unsigned integer in the interval [0,0xffffffff].
    		/// </summary>
    		/// <remarks>This is the core method that is used to generate other random numbers in
    		/// different normalized ranges.</remarks>
    		/// <returns>A random unsigned integer in the range [0,0xffffffff].</returns>
    		public uint genrand_int32()
    		{
    			uint y;
    
    			if (mti >= N)
    			{ /* generate N words at one time */
    				int kk;
    				if (mti == N+1)   /* if init_genrand() has not been called, */
    					init_genrand(5489U); /* a default initial seed is used */
    				for (kk=0;kk<N-M;kk++)
    				{
    					y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
    					mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1U];
    				}
    				for (;kk<N-1;kk++)
    				{
    					y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
    					mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1U];
    				}
    				y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
    				mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1U];
    				mti = 0;
    			}
    			y = mt[mti++];
    			/* Tempering */
    			y ^= (y >> 11);
    			y ^= (y << 7) & 0x9d2c5680U;
    			y ^= (y << 15) & 0xefc60000U;
    			y ^= (y >> 18);
    			return y;
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random signed integer in the range [0,0x7fffffff].
    		/// </summary>
    		public int genrand_int31()
    		{
    			return (int)(genrand_int32()>>1);
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random double in the real interval [0,1].
    		/// </summary>
    		public double genrand_real1()
    		{
    			return genrand_int32()*(1.0/4294967295.0); /* divided by 2^32-1 */ 
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random double in the real interval [0,1).
    		/// </summary>
    		public double genrand_real2()
    		{
    			return genrand_int32()*(1.0/4294967296.0); /* divided by 2^32 */
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random double in the real interval (0,1).
    		/// </summary>
    		public double genrand_real3()
    		{
    			return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0); /* divided by 2^32 */
    		}
    
    		//==========================================================================================
    		/// <summary>
    		/// Generates a random number in the real interval [0,1) with 53-bit resolution.
    		/// </summary>
    		public double genrand_res53()
    		{
    			uint a=genrand_int32()>>5, b=genrand_int32()>>6;
    			return(a*67108864.0+b)*(1.0/9007199254740992.0);
    		}
    		#endregion
    
    	}
    }

  14. #14
    Chaos silverx2's Avatar
    Join Date
    Jul 2002
    Location
    The hospital
    Posts
    1,262
    gee i really wish i had one of those counters, iv got a barrel of radioactive material and id like some random numbers.
    GhooooostGIrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrl
    https://signup.leagueoflegends.com?ref=4b5493e6c7342
    use the link above if you download league of legends.

  15. #15
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    Quote Originally Posted by asun2art
    I'll take it a step further, I've flopped a good hand on one window and raised on another thinking it was the first! THAT is pretty bad.
    haha. at the end of the day, it's just a maze game for gerbles, isn't it?

  16. #16
    Senior Member random25's Avatar
    Join Date
    Apr 2002
    Posts
    566
    I am Completely Random

    If you want to make an apple pie from scratch, you must first create the universe. Carl Sagan

  17. #17
    Banned indivision's Avatar
    Join Date
    Jul 2001
    Location
    Portland, OR
    Posts
    474
    lol

  18. #18
    Network Guy
    Join Date
    Nov 2004
    Posts
    36
    Most modern operating system use a combination of three or four inputs:
    1) The clock / timecounter / hardware pRNG
    2) The timing between packets on network interface
    3) The delay (seek time) in reading blocks from the hard drive
    4) The interrupts generated by mouse and keyboard

    On a very lightly loaded system without a hardware RNG, with no network interface, and no user controlled peripherals, random numbers generated are unlikely to be very random at all.

  19. #19
    Registered pseudo intellectual
    Join Date
    May 2005
    Location
    ol' Blighty
    Posts
    48
    Quote Originally Posted by Jeff2A
    On a very lightly loaded system without a hardware RNG, with no network interface, and no user controlled peripherals, random numbers generated are unlikely to be very random at all.
    Lol, how random do you mean by "unlikely to be very random"?

  20. #20
    Network Guy
    Join Date
    Nov 2004
    Posts
    36
    Quote Originally Posted by krona
    Lol, how random do you mean by "unlikely to be very random"?
    In the cryptographic realm, it would be weak enough for a determined and skilled intruder to predict an arbitrary value by watching a finite amount of traffic for a finite period of time. After watching some meaningful amount of traffic, the intruder would be able to determine a sequence, and using that, predict the CBC IV for upcoming crypto operations.

    In the realistic realm, most people would never notice, unless they were building a VPN appliance, a bank website, or creating SSH keys for CIA operatives to access protected networks from the field.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center