in this code I find available cars in simulation environment, for each available car, I selected the random number from 10 to 80 speeds to be assigned to each vehicle .
Then I use setspeed() and I set this random number as speed.
std::map<std::string, cModule*> availableCars = mobility->getManager()->getManagedHosts();
std::map<std::string, cModule*>::iterator it;
for(it = availableCars.begin(); it != availableCars.end(); it++){
TraCIMobility* mobility1 = TraCIMobilityAccess().get(it->second);
TraCICommandInterface::Vehicle* traciVehicle1=mobility1->getVehicleCommandInterface();
double select_random_speed=uniform(40,80);
std::cout<<"select random ="<<select_random_speed<<std::endl;
traciVehicle1->setSpeed(select_random_speed);
double GET_SPEED= mobility1->getSpeed();
std::cout<<"GET_SPEED"<<GET_SPEED<<std::endl;
}
But again, the outputs are close to 20.