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 uniform distribution) without having to scan the whole list (in the worst case) twice (i.e. to get its length and to reach the selected node after having randomly selected its position)?
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;
};