Thread: Random number generator

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    9

    Random number generator

    All fixed! Thanks!
    Last edited by bond_006; 03-24-2010 at 10:57 AM.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    1) The `new' operator doesn't return `null' so checking for `null' isn't useful.

    2) You aren't assigning any values to the array. (Which is a damned good thing considering that you are guaranteed to access memory you don't own.)

    Soma

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    d

    Code:
    fill a with random numbers
    	for ( int i = 0 ; i < size ; i++ )
    		array1[ rand() ] ;
    that rand() call is not in a good place
    and i thought srand time null, not 0 ? i dunno if that makes much difference though, i just sticks wit wot i knows on the rand num generation

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Please don't delete your posts as soon as you think you've got an answer:
    - your answer might be wrong (no one else can check or contribute)
    - all the replies are meaningless
    - no one else can learn (how selfish of you).
    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.

  5. #5
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    One relevant part is in the second response.

    Code:
    int * array1;
    // ...
    array1 = new int[size]; if(!array) exit(1);
    That code is other relevant bit.

    Maybe we can get an administrator to "repair" the context of the original post.

    Soma

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Good Random Number Generator
    By MethodMan in forum C Programming
    Replies: 4
    Last Post: 11-18-2004, 06:38 AM
  3. How do I restart a random number sequence.
    By jeffski in forum C Programming
    Replies: 6
    Last Post: 05-29-2003, 02:40 PM
  4. how to link random number generator with cpu?
    By chris285 in forum C++ Programming
    Replies: 5
    Last Post: 04-28-2003, 05:26 AM
  5. Seeding Random Number Generator
    By zdude in forum C++ Programming
    Replies: 2
    Last Post: 09-05-2002, 03:10 PM