Autor Beitrag
Waldkauz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Di 23.06.09 22:33 
Hallo!

Ist es möglich, Zufallszahlen aus einem gewissen Bereich zu erstellen?
Also so in der Art random(45-100) - Zufallszahlen zwischen 45 und 100
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 23.06.09 22:34 
ausblenden Delphi-Quelltext
1:
Random(55) + 45					
Mit der Addition verschiebst du den Bereich von 0 als Startwert hin zu 45, und alle erhaltenen Zahlen entsprechend.
Waldkauz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Di 23.06.09 22:34 
merci ^^ - logisch eigentlich
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19326
Erhaltene Danke: 1749

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 23.06.09 22:36 
Theoretisch gibts übrigens auch noch RandomRange als Befehl in der Unit Math, aber das macht (logischerweise) auch nix anderes.
www.delphibasics.co....&ExpandCode1=Yes
ub60
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 764
Erhaltene Danke: 127



BeitragVerfasst: Di 23.06.09 23:50 
Also zwischen 45 und 100 wäre von 46 bis 99.

Die Formel dazu wäre:

ausblenden Delphi-Quelltext
1:
Zahl:=Random(54) + 46;					

Der Bereich von 45 bis 100 wäre dann:

ausblenden Delphi-Quelltext
1:
Zahl:=Random(56) + 45;					

ub60