Whiz Tools

Generator ya Mahali ya Nasibu

Mzizi wa Mahali wa Nasibu

[... yaliyomo yaliyopo ...]

Uwakilishi wa Kitaalamu

Ili kutoa muktadha wa kuona kwa kuratibu zilizozalishwa, tunatekeleza ikoni rahisi ya dunia kwa kutumia SVG. Hapa kuna mfano wa jinsi hii inaweza kufanywa:

SVG hii inaunda dunia rahisi yenye mistari ya latitudo na longitudo, na alama nyekundu ikiwakilisha mahali lililotolewa. Nafasi halisi ya alama inaweza kuhesabiwa kulingana na kuratibu zilizozalishwa.

[... yaliyomo yaliyopo ...]

Mifano

Hapa kuna mifano ya msimbo wa kuzalisha kuratibu za nasibu katika lugha mbalimbali za programu:

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');
?>

Utekelezaji wa Kitufe cha Nakala

Ili kutekeleza kazi ya Kitufe cha Nakala, tunaweza kutumia API ya Clipboard. Hapa kuna mfano rahisi wa JavaScript:

function copyToClipboard(text) {
  navigator.clipboard.writeText(text).then(() => {
    alert('Kuratibu zimeandikwa kwenye clipboard!');
  }, (err) => {
    console.error('Haiwezekani kunakili maandiko: ', err);
  });
}

// Matumizi
const copyButton = document.getElementById('copyButton');
copyButton.addEventListener('click', () => {
  const coordinates = document.getElementById('coordinates').textContent;
  copyToClipboard(coordinates);
});

Kazi hii inaweza kuitwa wakati Kitufe cha Nakala kinabonyezwa, ikipitia kuratibu zilizozalishwa kama maandiko yanayopaswa kunakiliwa.

[... yaliyomo yaliyopo ...]

Loading related tools...
Feedback