Ich möchte random.random() verwenden, um zufällige Gleitkommazahlen zu generieren und die Ausgabe mit etwas Mathe zu ändern, so dass Sie schließlich -100 zu +100 erhalten. Unter Verwendung der Mathematik möchte ich Multiplikation und Subtraktion verwenden, um drei zufällige Gleitkommazahlen innerhalb eines Bereichs von -100 bis +100 zu erzeugen.Random Floats von -100 bis 100 mit zufälliger Zufall
hier ist mein Code:
import random
random_float = (random.random())
print("First random float between -100 and +100:", random_float - 10)
print("Second random float between -100 and +100:", random_float * 70)
print("Third random float between -100 and +100:", random_float * 100)
hier ist meine Ausgabe:
First random float between -100 and +100: -9.932043497731886
Second random float between -100 and +100: 4.756955158768027
Third random float between -100 and +100: 6.795650226811468
dieses Recht aus?
Ich bin verwirrt, warum Sie all das tun * 70 und -10? Wenn Sie drei zufällige float von -100 bis 100 wollen, wiederholen Sie einfach die gleiche Sache dreimal "random_float * 100" – Bobby
Was ist Ihre Frage genau? –
@Bobby Müsste es nicht 200 sein (random.random() - 0.5) '? – Tagc