Thread: Vector class

  1. #1
    Unregistered
    Guest

    Vector class

    Ok maybe this time I'll actually post to the right board.

    Is there a STL method which will return a random element from a vector? Its easy enough to write such a method, but I was just wondering if one exists already. I've searched on google to no avail.
    Thanks.

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    66

    random

    The whole point of a vector is to have sequential predictable access in O(1).

    If you want random access to a member you can always do:

    std::vector v;

    ...

    v[(int)(rand()*v.size())]

    ...

    or similar depending how random you want it (rand is not new random as you know

  3. #3
    Shadow12345
    Guest
    what is STL?

Popular pages Recent additions subscribe to a feed