Thread: Using variable overflow for random numbers - wise?

  1. #1
    Math wizard
    Join Date
    Dec 2006

    Using variable overflow for random numbers - wise?

    I'm just wondering about something. Is it possible to use rather weird formulas to generate random numbers, formulas that cause variable overflow and use variables users have little control over? For example (the concept):

    int randomize(int min_range, int max_range, float seed)
    	int result;
    	// obtain time since program has started (likely in milliseconds, maybe microseconds; as a float)
    	// obtain current system time (minutes and seconds values; as a char)
    	// obtain another variable or two one doesn't have control over and is hidden, from 0.001 to 16
    	seed %= 1E09; // up to a billion
    	program_time %= 5;
    	result = ((pow(another_var, program_time) + system_time*another_var * seed) % (max_range+min_range)) + min_range;
    	return (result);
    Would the idea work? Would it be safe to do (considering variable overflow is a near-certainty)?
    Last edited by ulillillia; 12-17-2006 at 01:13 PM. Reason: Changed subject to be more accurate

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Which would be no better than the usual crop of LC generators

    Time is not a very good source for randomness, due to its predictable nature.

    Strictly speaking, integer overflow is allowed to cause a trap, but in practice, very few machines do it.

    > Would the idea work?
    I doubt it would pass a whole battery of tests designed to test how good a random number generator really is.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 03-03-2003, 03:52 PM
  2. the definition of a mathematical "average" or "mean"
    By DavidP in forum A Brief History of
    Replies: 7
    Last Post: 12-03-2002, 11:15 AM
  3. Reading selective numbers from a file
    By supaben34 in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2002, 01:56 PM
  4. A (complex) question on numbers
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 02-03-2002, 06:38 PM
  5. Replies: 7
    Last Post: 01-02-2002, 09:16 PM