| wdmd1982 (22) | |
|
hello guys it's been a long time, i have a problem, i need to generate random values, but these values need to be coordinates (x,y) i would like to hear ideas about how to do it? Thanks a lot for any suggestion | |
|
|
|
| firedraco (5414) | |
| Use rand(). | |
|
|
|
| hannes (97) | |
|
rand() % number number is the max number you want | |
|
|
|
| wdmd1982 (22) | |
|
Thanks for your answers but i think it is my fault not being more precisly!!!! this is my problem I generate a two dimension array static and then create ramdonly number but when i try to do the same thing using a dinamic array i got problems.. this is what i got int Number_nodes; int dimension; int max_distance; int* nodes; int i,j; printf("Please enter the number of nodes, dimension and maximum distance. "); scanf("%d %d %d",&Number_nodes, &dimension, &max_distance); nodes= (int *)malloc(sizeof(int)*Number_nodes); for(j=0;j<Number_nodes;j++){ nodes[j]=(int *)malloc(sizeof(int)*Number_nodes); } for(i=0;i<Number_nodes;i++){ for(j=0;j<Number_nodes;j++){ nodes[i][j]=rand() % dimension;; printf("File: %d Columm: %d %d\n",i,j,nodes[i][j]); } } free(nodes); Thanks beforehand for your help!!!! | |
|
Last edited on
|
|
| mspy2plus (28) | |||
|
use srand() to seed your random. also, use code brackets so that int main() becomes
| |||
|
Last edited on
|
|||