| 4582 | def random_vertex(self,**kwds): |
| 4583 | r""" |
| 4584 | Returns a random vertex. |
| 4585 | |
| 4586 | INPUT: |
| 4587 | |
| 4588 | - ``**kwds`` -- arguments to be passed down to the |
| 4589 | ``vertex_iterator`` method. |
| 4590 | |
| 4591 | EXAMPLE: |
| 4592 | |
| 4593 | The returned value belong to the set of vertices:: |
| 4594 | |
| 4595 | sage: g = graphs.PetersenGraph() |
| 4596 | sage: v = g.random_vertex() |
| 4597 | sage: v in g |
| 4598 | True |
| 4599 | """ |
| 4600 | |
| 4601 | from sage.misc.prandom import randint |
| 4602 | it = self.vertex_iterator(**kwds) |
| 4603 | for i in xrange(0, randint(0,self.order()-1)): |
| 4604 | it.next() |
| 4605 | |
| 4606 | return it.next() |
| 4607 | |
| 4608 | def random_edge(self,**kwds): |
| 4609 | r""" |
| 4610 | Returns a random edge. |
| 4611 | |
| 4612 | INPUT: |
| 4613 | |
| 4614 | - ``**kwds`` -- arguments to be passed down to the |
| 4615 | ``edge_iterator`` method. |
| 4616 | |
| 4617 | EXAMPLE: |
| 4618 | |
| 4619 | The returned value belong to the set of edges:: |
| 4620 | |
| 4621 | sage: g = graphs.PetersenGraph() |
| 4622 | sage: u,v = g.random_edge(labels=False) |
| 4623 | sage: g.has_edge(u,v) |
| 4624 | True |
| 4625 | |
| 4626 | As the ``edges()`` method would, this function returns |
| 4627 | by default a triple ``(u,v,l)`` of values, in which |
| 4628 | ``l`` is the label of edge `u,v` :: |
| 4629 | |
| 4630 | sage: g.random_edge() |
| 4631 | (...,...,...) |
| 4632 | """ |
| 4633 | |
| 4634 | from sage.misc.prandom import randint |
| 4635 | it = self.edge_iterator(**kwds) |
| 4636 | for i in xrange(0, randint(0,self.size()-1)): |
| 4637 | it.next() |
| 4638 | |
| 4639 | return it.next() |
| 4640 | |