samedi 7 décembre 2019

generate random numbers within a range with a percentage of them a specific value

I need to create large (see more on this below) random graphs to compare performance of Dijkstra, Bellman-Ford, and Floyd's algorithms on shortest path graph traversal. I'm storing the adjacencies in an array. So far, I generated random weights between vertices, and filled the main diagonal with 0's. I also have symmetry about the main diagonal (I'm assuming the graphs are undirected but not necessarily completely connected).

The random values are in the range 0 - 24 ish, generated using rand() % 25. The problem is that I'd like the graphs to be sparser (i.e. have less edges). Is there a way to generate random numbers within a range and have about 1/3 to 1/2 of the generated numbers be a specific value? Note that the random distribution isn't very important for what I'm doing...

Another question: how large of a graph should I test to see performance differences? 10 vertices? 100? 1000? 10000000?




Aucun commentaire:

Enregistrer un commentaire