I have a list and I want to randomly select a node from it. As it's not an array I don't know in advance its length. Is there a way to select a node randomly (with homogeneous distribution) without having to scan the whole list in order to get its length?
Here's the code I use for my list:
struct mynode {
in_addr_t paddr;
struct mynode *prev, *next;
};
struct mylist {
struct mynode *first, *last;
char *name;
};
Aucun commentaire:
Enregistrer un commentaire