import random
def generate_random_coordinates():
latitude = random.uniform(-90, 90)
longitude = random.uniform(-180, 180)
return latitude, longitude
lat, lon = generate_random_coordinates()
print(f"{lat:.4f}° {'N' if lat >= 0 else 'S'}, {abs(lon):.4f}° {'E' if lon >= 0 else 'W'}")
function generateRandomCoordinates() {
const latitude = Math.random() * 180 - 90;
const longitude = Math.random() * 360 - 180;
return { latitude, longitude };
}
const { latitude, longitude } = generateRandomCoordinates();
console.log(`${latitude.toFixed(4)}° ${latitude >= 0 ? 'N' : 'S'}, ${Math.abs(longitude).toFixed(4)}° ${longitude >= 0 ? 'E' : 'W'}`);
import java.util.Random;
public class RandomCoordinateGenerator {
public static double[] generateRandomCoordinates() {
Random random = new Random();
double latitude = random.nextDouble() * 180 - 90;
double longitude = random.nextDouble() * 360 - 180;
return new double[]{latitude, longitude};
}
public static void main(String[] args) {
double[] coordinates = generateRandomCoordinates();
System.out.printf("%.4f° %s, %.4f° %s%n",
Math.abs(coordinates[0]), coordinates[0] >= 0 ? "N" : "S",
Math.abs(coordinates[1]), coordinates[1] >= 0 ? "E" : "W");
}
}
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
std::pair<double, double> generateRandomCoordinates() {
double latitude = (static_cast<double>(rand()) / RAND_MAX) * 180 - 90;
double longitude = (static_cast<double>(rand()) / RAND_MAX) * 360 - 180;
return {latitude, longitude};
}
int main() {
srand(time(0));
auto [lat, lon] = generateRandomCoordinates();
std::cout << std::fixed << std::setprecision(4)
<< std::abs(lat) << "° " << (lat >= 0 ? "N" : "S") << ", "
<< std::abs(lon) << "° " << (lon >= 0 ? "E" : "W") << std::endl;
return 0;
}
def generate_random_coordinates
latitude = rand(-90.0..90.0)
longitude = rand(-180.0..180.0)
[latitude, longitude]
end
lat, lon = generate_random_coordinates
puts format("%.4f° %s, %.4f° %s",
lat.abs, lat >= 0 ? 'N' : 'S',
lon.abs, lon >= 0 ? 'E' : 'W')
<?php
function generateRandomCoordinates() {
$latitude = mt_rand(-90 * 10000, 90 * 10000) / 10000;
$longitude = mt_rand(-180 * 10000, 180 * 10000) / 10000;
return [$latitude, $longitude];
}
list($lat, $lon) = generateRandomCoordinates();
printf("%.4f° %s, %.4f° %s\n",
abs($lat), $lat >= 0 ? 'N' : 'S',
abs($lon), $lon >= 0 ? 'E' : 'W');
?>