Click here to Skip to main content
15,878,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have generated a series of number , how to randomly assign name to it from a set of name. Let say I have, Vertex [i]: n,
Vertex [0]: 1
Vertex [1]: 5
Vertex[2]: 9
Vertex[19]: 13

and a set of name : { apple, orange, papaya, watermelon, pineapple}

And what I want to do is when I key in 0 ( i value) which is for the first item, it will print 
Vertex [0]: 1 { orange } 
means it will pick one name from the list and random assign to n 

What I have tried:

    printf("Number of Edges for each node:\n");
    for( i = 0 ; i < N ; i++ )
        printf("Vertex %d: ",i);
        for( j = 0 ; j < N ; j++ )
                n+=1;  ////count the number of repeat

        if(n<min)min=n; printf("%d="" ",="" n);="" printf("\n"); 
Updated 22-Oct-16 6:39am

1 solution

You must build a name list with all possible names and than use some modified random value to use a name. And if the name is picked, delete it from that list. So it will be unique.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900