Autor Beitrag
Udontknow
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2596

Win7
D2006 WIN32, .NET (C#)
BeitragVerfasst: Mo 22.08.05 12:09 
Hallo!

Zu 1:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var r:real;
begin
  r:=random;
  ShowMessage(FloatToStr(r));
end;


Zu 2:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var r:real;
begin
  r:=random*5+10;
  ShowMessage(FloatToStr(r));
end;


Cu,
Udontknow
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 15:00 
so der erste quellcode klappt aber bei dem 2 hab ich noch probleme da hab ich jetzt eine variable hin geschrieben wert integer und da merkert der rum



ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
bla,sülz,kartoffeln : integer;
begin
sülz := 5
kartoffeln:= 10

      bla := random * sülz + kartoffeln;



[Fehler] Unit1.pas(132): Inkompatible Typen: 'Integer' und 'Extended'

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 15:03 
die var bla, is'n Integerwert -> ganzzahliger Wert.
Random() gibt aber n extended-wert zurück -> Kommazahl
Und daher sollte bla auch extended sein, dann gehts.
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 15:14 
Jetzt kann ich damit aber nett weiter rechnen gibt es da nicht irgend was von Komma zu ganz Zahl so wie FloattoInt oder so.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 22.08.05 15:19 
Geht doch schon mit den hier genennaten Lösungen:

ausblenden Delphi-Quelltext
1:
Result := 10 + 5 * Random;					


Macht schon das, was Du willst. Allerdings ist hier 15 nicht enthalten: 10 <= x < 15

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 15:22 
Zitat:
Jetzt kann ich damit aber nett weiter rechnen gibt es da nicht irgend was von Komma zu ganz Zahl so wie FloattoInt oder so.

Wenn du n eKommazahl in ne ganzzahl umwandelst kommt nie der Gleiche wert raus, außer die Kommazahl war 2,00 :lol:
Du könntest den wert allerdings runden.
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 15:29 
@BenBE die zahl die dann raus kommt ist eine kommazahl und das mog ih nett hab sonst nur integer zahlen und das verträgt sich ja nicht so gut.

Runden? und wie geht das?
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 22.08.05 15:34 
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 22.08.05 15:35 
Was sagt die OH zu runden? Tipp: Round();

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 16:31 
Ich kotz gleich hab deine Function benutzt und de rbringt mir entweder zu viele Parameter obwohl ich dem 2 Stück gebe oder denn hier

[Fehler] Unit1.pas(39): Ungenügende Forward- oder External-Deklaration: 'TFrm_Game.RandomRange'
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 16:39 
Zeig den Source
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 16:44 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
  private
    function RandomRange: integer;


procedure TFrm_Game.fight_click(Sender: TObject);
var att:integer;

      att := randomrange(iM_mi_att, iM_ma_att);



function RandomRange(min, max: integer): integer;
begin
  result := 0;
  if min > max then
    exit;
  result := random(max - min + 1) + min;
end;


so nach dem Schema eben.

Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 16:48 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
  private
    function RandomRange: integer;


procedure TFrm_Game.fight_click(Sender: TObject);
var 
att:integer;
begin
att := randomrange(iM_mi_att, iM_ma_att);
end;


function TFrm_Game.RandomRange(min, max: integer): integer;
begin
  result := 0;
  if min > max then
    exit;
  result := random(max - min + 1) + min;
end;
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 22.08.05 16:55 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
type
(*...*)
  private  
    function RandomRange: integer;  
 
(*...*)
 
function TFrm_Game.RandomRange(min, max: integer): integer;  
begin  
  result := 0;  
  if min > max then  
    exit;  
  result := random(max - min + 1) + min;  
end; 
 
procedure TFrm_Game.fight_click(Sender: TObject);  
var   
  att:integer;  
begin  
  att := randomrange(iM_mi_att, iM_ma_att);  
end;
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 17:01 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
private
function RandomRange :integer;

function TFrm_Game.RandomRange(min, max: integer): integer;


verstehe ich nicht.

[Fehler] Unit1.pas(176): Deklaration von 'RandomRange' unterscheidet sich von vorheriger Deklaration

ist beides das gleich und wenn ich eins von beiden lösche funzt das andere nett!
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 22.08.05 17:03 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
private
function RandomRange(min, max: integer) :integer;

function TFrm_Game.RandomRange(min, max: integer): integer;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 17:04 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
private
function RandomRange(min, max: integer) :integer;

function TFrm_Game.RandomRange(min, max: integer): integer;


EDIT: Menno, zu langsam!


Zuletzt bearbeitet von Fabian W. am Mo 22.08.05 17:04, insgesamt 1-mal bearbeitet
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mo 22.08.05 17:04 
stimmt hab ich übersehen :wink:
Beutel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 89

WIN XP

BeitragVerfasst: Mo 22.08.05 17:14 
Danke hat geklappt.
Hätte es aber auch mir denken können!
Viel glück denn anderen noch!