Random Numbers

This is a discussion on Random Numbers within the C++ Programming forums, part of the General Programming Boards category; since random is the name of a function it might cause a name conflict if you name your function random. ...

  1. #16
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    since random is the name of a function it might cause a name conflict if you name your function random. When you know that there is a function by a given name it is best to use a different one for yours. Otherwise, sure, you could use the name curleyCue for rand_mid if you want.

  2. #17
    Confused
    Join Date
    Nov 2002
    Location
    Warwick, UK
    Posts
    209
    There is a function called RANDOM, what does it do and how do I use it ?

  3. #18
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    If you are writing your own function which is called random(), but also want to use random from stdlib.h why not use the resolution operator so the compiler knows which function you are refering to e.g.

    Code:
    void random()
    {
      randomize():
    
      int Num = ::random(500);
    
    }
    Along them lines anyway....
    Be a leader and not a follower.

  4. #19
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by subdene
    If you are writing your own function which is called random(), but also want to use random from stdlib.h why not use the resolution operator so the compiler knows which function you are refering to e.g.

    Code:
    void random()
    {
      randomize():
    
      int Num = ::random(500);
    
    }
    Along them lines anyway....
    No no no! Actually read this thread and you'd find out that random and randomize are NOT standard ANSI functions. Not all compilers have those functions. They are not a part of the standard stdlib header. They are Borland functions. Period.

    It is usually considered a bad idea to tell people to use non-standard functions for simple tasks like number generation. Somethin more specific like graphics manipulations, sure, use your custom library, but don't suggest people use non-standard functions for learning the basics.

    Furtheremore, what's with the double :: in your post?

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #20
    Registered User Nippashish's Avatar
    Join Date
    Sep 2002
    Posts
    34
    Originally posted by quzah
    Furtheremore, what's with the double :: in your post?
    It's directing the compiler to the global namespace.

    ex:
    Code:
    #include <iostream>
    
    int bar()
    {
    	return 5;
    }
    
    namespace foo
    {
    	int bar()
    	{
    		return ::bar();
    	}
    }
    
    int main()
    {
    	std::cout << foo::bar();
    	return 0;
    }

  6. #21
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    really...... well i did say:

    Are they just not part of the standard and are therefore just not used?
    oh can't be arsed with this..... wheres the pub.....
    Be a leader and not a follower.

  7. #22
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Originally posted by Nippashish
    It's directing the compiler to the global namespace.

    ex:
    Code:
    #include <iostream>
    
    int bar()
    {
    	return 5;
    }
    
    namespace foo
    {
    	int bar()
    	{
    		return ::bar();
    	}
    }
    
    int main()
    {
    	std::cout << foo::bar();
    	return 0;
    }
    But it was already scoped to the global namespace, so there was really no point.

  8. #23
    Much older and wiser Fountain's Avatar
    Join Date
    Dec 2001
    Location
    Engeeeerland
    Posts
    1,158
    Originally posted by subdene
    How come no-one seems to use randomize() and random() these days from stdlib.h. Are they just not part of the standard and are therefore just not used?
    Read the question posted, and leave sub alone. I understood the question!
    Such is life.

  9. #24
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Originally posted by Fountain
    Read the question posted, and leave sub alone. I understood the question!
    Don't get your panties in a bunch. No one is "picking on" anyone. When you do something in example code, you'd better be ready to provide reasoning behind your doing it.

    The question I asked was "Why the :: in your example?" It's been explained and found that there is no real need for them. We call this "learning" around here, or perhaps better "learning by discussion or example".

    Your question has already been answered. You should reread this thread, paying particular attention to Prelude's post.

    Instead of trying to be Mr. Defender Of The Universe, try actually paying attention to what's going on. You'll learn more that way.


    Quzah.
    Hope is the first step on the road to disappointment.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. Doubts regarding random numbers generation
    By girish1026 in forum C Programming
    Replies: 9
    Last Post: 12-31-2008, 09:47 PM
  3. random numbers limit
    By HAssan in forum C Programming
    Replies: 9
    Last Post: 12-06-2005, 06:51 PM
  4. Generate random numbers in Lucky7 project using C#
    By Grayson_Peddie in forum C# Programming
    Replies: 1
    Last Post: 04-11-2003, 11:03 PM
  5. random numbers
    By lil_plukyduck in forum C++ Programming
    Replies: 5
    Last Post: 01-14-2003, 09:14 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21