I am looking for a RANDOM function...
Author 
Message 
Klaus Kristens #1 / 20

I am looking for a RANDOM function...
I am looking for a function to generate random numbers between two values. Ex. Min := 200000.00 Max := 299999.99 Random(Min, Max) => 139529.27 (Output) Do you have such a function in source code please let me know or send it to me, if it is OK with you. Thanks in advance. Best regards, Klaus Kristensen Denmark in Europe

Wed, 18 Jun 1902 08:00:00 GMT 


Terry Sik #2 / 20

I am looking for a RANDOM function...
Quote:
>>I am looking for a function to generate random numbers >>between two values. >>Ex. >>Min := 200000.00 >>Max := 299999.99 >>Random(Min, Max) => 139529.27 (Output) >Dear Klaus >Assuming that you have Pascal, it is quite easy to write a piece of code >for this function and if you look in the HELP directory you will find it >contained here. If you wish it to be between two parameters then you >can easily use a loop, so as to keep repeating untill it is between >those numbers. >If you still have problems please feel free to contact me.
I'm most likely completing someone's homework assignment here (shame!) but I wanted to correct the impression that a loop may be required. The code should look something like this: result := (max  min) * Random() + min; Random() with no argument returns a realtype (now that I look at the docs I'm not sure what this means, I'd assume double...anyone?) value 0 <= x < 1. Call Randomize() before you call Random() the first time if you don't want the sequence to repeat each time you run the program. Hope this helped!  Terry Sikes  Software Developer
finger for PGP pub key  "Anyone programming in a 16bit environment My opinions  mine only!  isn't playing with a full DEC."

Wed, 18 Jun 1902 08:00:00 GMT 


Mark Vaugh #3 / 20

I am looking for a RANDOM function...
]I am looking for a function to generate random numbers ]between two values. ] ] ]Ex. ] ]Min := 200000.00 ]Max := 299999.99 ] ]Random(Min, Max) => 139529.27 (Output) ] ] ]Do you have such a function in source code please let ]me know or send it to me, if it is OK with you. how 'bout this... Function BoundedRandom(Min, Max : double) : double; BEGIN {==BoundedRandom==} result := random*(Max  Min) + Min; END; {==BoundedRandom==} only problem might be that the builtin "random" function returns X  0 <= X < 1, so while BoundedRandom can return Min it cannot return Max. (Of course if min and max can't be exactly represented as a floating point number then you'll have problems at the end points anyway...) Mark Vaughan ] ]Thanks in advance. ] ] ]Best regards, ] ]Klaus Kristensen ]Denmark in Europe

Wed, 18 Jun 1902 08:00:00 GMT 


Neil Jaque #4 / 20

I am looking for a RANDOM function...
Quote: >I am looking for a function to generate random numbers >between two values. >Ex. >Min := 200000.00 >Max := 299999.99 >Random(Min, Max) => 139529.27 (Output)
Dear Klaus Assuming that you have Pascal, it is quite easy to write a piece of code for this function and if you look in the HELP directory you will find it contained here. If you wish it to be between two parameters then you can easily use a loop, so as to keep repeating untill it is between those numbers. If you still have problems please feel free to contact me. From Neil
 Neil Jaques 01420 474290

Wed, 18 Jun 1902 08:00:00 GMT 


tant #5 / 20

I am looking for a RANDOM function...
Quote:
> ]I am looking for a function to generate random numbers > ]between two values. > how 'bout this... > Function BoundedRandom(Min, Max : double) : double; > BEGIN {==BoundedRandom==} > result := random*(Max  Min) + Min; > END; {==BoundedRandom==} > only problem might be that the builtin "random" function > returns X  0 <= X < 1, so while BoundedRandom can return > Min it cannot return Max. (Of course if min and max can't > be exactly represented as a floating point number then > you'll have problems at the end points anyway...) > Mark Vaughan
try this, it will bound between the min and max region function gen_random(min, max : integer) : integer; begin result := (max  min + 1) * Random + min; end. tanthalas

Wed, 18 Jun 1902 08:00:00 GMT 


John De Beer / D. Mona Baumgart #6 / 20

I am looking for a RANDOM function...
Quote:
>I am looking for a function to generate random numbers >between two values. >Ex. >Min := 200000.00 >Max := 299999.99 >Random(Min, Max) => 139529.27 (Output) >Do you have such a function in source code please let >me know or send it to me, if it is OK with you. >Thanks in advance. >Best regards, >Klaus Kristensen >Denmark in Europe
procedure TForm1.Button1Click(Sender: TObject); {add button and 2 labels to your form} var r,x,y,z:real; begin r := random; {create random number} x := 200000.00 ; {Lowest number} Y := 499999.99 ; {diff lowest to highest} z := x + y*r ; {calc value} label1.caption := floattostrf(z,fffixed,7,2); {display value on label} label2.caption := floattostrf(r,fffixed,7,2); {display random on label} end; procedure TForm1.Button2Click(Sender: TObject); {ADD BUTTON2, LABEL3, AND 2 EDIT BOXES TO YOUR FORM} VAR x,y: real; begin if (Edit1.text <> '') and (Edit2.Text <> '' ) then begin x := StrToFloat( Edit1.text); y := StrToFloat(Edit2.text); MakeRandom(X,Y); Label3.Caption := floattostrf(MakeRandom(X,Y),fffixed,7,2); end else MessageDlg('Need some values', mtInformation, [mbCancel], 0); end; function MakeRandom(X,Y:Real):real; begin result := x + y*random; {calc value} end; procedure TForm1.FormCreate(Sender: TObject); begin Edit1.Text := ''; Edit2.Text := ''; end; end.

Wed, 18 Jun 1902 08:00:00 GMT 


John De Beer / D. Mona Baumgart #7 / 20

I am looking for a RANDOM function...
Sorry got late, forgot question; should be; function MakeRandom(rmin,rmax:Real):real; begin result := rmin + (rmaxrmin)*random; {calc value} end;

Wed, 18 Jun 1902 08:00:00 GMT 


Larry Hadl #8 / 20

I am looking for a RANDOM function...
: Ex. : Min := 200000.00 : Max := 299999.99 : Random(Min, Max) => 139529.27 (Output) Use the Random() function. Determine the *range* between the two numbers, use this information to generate a random number the same size *as the range*. Add in the value of the the "min" parameter. Presto! eg: size := maxmin; n := Random(size); n := n+min; 
Visit my homepage, get HTMLStrip and PMove: http://www.knet.flemingc.on.ca/~lhadley/Profile.html Microsoft Network is prohibited from redistributing this work in any form, in whole or in part. Copyright, Larry Hadley, 1996. Please send notices of

Wed, 18 Jun 1902 08:00:00 GMT 


Shai Benjami #9 / 20

I am looking for a RANDOM function...
It is my experience that the compiler's 'random' function is too correlated. If you need to use it many times (define many your own way) you need to decorrelate it by using the following: const N=4; { the higher N the lower the correlation (and also the speed). I usually use N=4. } function MyRandom:real; var i,r:integer; begin r:=random(N); { generates an integer in the range 0..N1 } for i:=0 to r do MyRandom:=random; end; Don't forget to 'randomize'. Now, how to generate different distributions (e.g. Uniform, Exponential, Normal etc.) is the subject for a whole seperate posting. Shai.

Wed, 18 Jun 1902 08:00:00 GMT 


Svante Granqvis #10 / 20

I am looking for a RANDOM function...
Quote:
> It is my experience that the compiler's 'random' function > is too correlated. If you need to use it many times > (define many your own way) you need to decorrelate it > by using the following:
Interesting... How would you show that? Is it just a "feeling" that it's correlated, or do you have an example when this correlation makes trouble for you?  Svante Granqvist Speech, Music and Hearing Phone +468790 7561 Box 700 14 Fax +468790 7854 S100 44 Stockholm

Wed, 18 Jun 1902 08:00:00 GMT 


Shai Benjami #11 / 20

I am looking for a RANDOM function...
Quote:
> > It is my experience that the compiler's 'random' function > > is too correlated. If you need to use it many times > > (define many your own way) you need to decorrelate it > > by using the following: > > ... > Interesting... How would you show that? Is it just a "feeling" that > it's correlated, or do you have an example when this correlation > makes trouble for you?
As I said, it is purely based on experience ! I once wrote a short simulation that generates random bits and inserts a fixed pattern once every M bits (a frame). I then looked for the probability of a random occurance of the fixed pattern elsewhere in the frame. This probability is 'quite' easy to calculate (it depends on the cyclic characteristics of that fixed pattern). Now, without the decorrelation procedure I described in the previous posting I got odd results from the simulation while decorrelating fit the calculations. Shai.

Wed, 18 Jun 1902 08:00:00 GMT 


Sven Pr #12 / 20

I am looking for a RANDOM function...
Quote:
>> > It is my experience that the compiler's 'random' function >> > is too correlated. >> Interesting... How would you show that? >As I said, it is purely based on experience ! >I once wrote a short simulation that generates random bits and inserts >a fixed pattern once every M bits (a frame). I then looked for the >probability of a random occurance of the fixed pattern elsewhere in >the frame. This probability is 'quite' easy to calculate (it depends on >the cyclic characteristics of that fixed pattern). Now, without the >decorrelation procedure I described in the previous posting I got odd >results from the simulation while decorrelating fit the calculations. >Shai.
This just confirms one of the most important issues with pseudorandom generators: Even the very best generators are predictable because after all they ARE based upon calculations. This means that first you will have to select a presumably good generator, and then you have to test it with the actual application to verify that the generator works well also there. Finally you should use some monitoring means to verify during the life of your application that the results are reasonable (which can be really difficult). The fact that the generator seems to fail in a particular application does not neccessarily imply that it is bad, only that some unhappy correlation might exist between that particular application and the generating formula. Your experience is a bit surprising though: I failed to find any serial correlation once I tried the usual tests on every second, third, fourth and so on output from RANDOM. (The formula used is such that you wouldn't expect any serial correlation). regards Sven

Wed, 18 Jun 1902 08:00:00 GMT 


Matthew B. Com #13 / 20

I am looking for a RANDOM function...
Quote:
>>I am looking for a function to generate random numbers >>between two values. >>Ex. >>Min := 200000.00 >>Max := 299999.99 >>Random(Min, Max) => 139529.27 (Output)
use: Random(1) * Range + LowerBound so, for 5<x<5, use Random(1) * 10  5 Matt

Wed, 18 Jun 1902 08:00:00 GMT 


David Ullric #14 / 20

I am looking for a RANDOM function...
Quote:
> >>I am looking for a function to generate random numbers > >>between two values. > >>Ex. > >>Min := 200000.00 > >>Max := 299999.99 > >>Random(Min, Max) => 139529.27 (Output) > use: > Random(1) * Range + LowerBound > so, for 5<x<5, use > Random(1) * 10  5 > Matt
I think you meant Random here, not Random(1). Random(1) is an _integer_ satisfying 0 <= Random(1) < 1 , which is really not all that random. (If you don't believe it try this: var j:integer;Oops:Bool; begin Oops:=True; for j:=1 to 100 do if Random(1)<>0 then Oops:=False; if Oops then ShowMessage('Oops...'); end; )  David Ullrich Sig file accidentally deleted  sorry.

Wed, 18 Jun 1902 08:00:00 GMT 


John De Beer / D. Mona Baumgart #15 / 20

I am looking for a RANDOM function...
Quote:
>I am looking for a function to generate random numbers >Klaus Kristensen >Denmark in Europe
try this. Sorry I got carried away playing with this. unit Ranumber; interface uses SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Button1: TButton; Label2: TLabel; Edit1: TEdit; Edit2: TEdit; Button2: TButton; Label3: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; function MakeRandom(X,Y:Real):real; var Form1: TForm1; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); {add button and 2 labels to your form} var r,x,y,z:real; begin r := random; {create random number} x := 200000.00 ; {Lowest number} Y := 499999.99 ; {diff lowest to highest} z := x + y*r ; {calc value} label1.caption := floattostrf(z,fffixed,7,2); {display value on label} label2.caption := floattostrf(r,fffixed,7,2); {display random on label} end; procedure TForm1.Button2Click(Sender: TObject); {ADD BUTTON2, LABEL3, AND 2 EDIT BOXES TO YOUR FORM} VAR x,y: real; begin if (Edit1.text <> '') and (Edit2.Text <> '' ) then begin x := StrToFloat( Edit1.text); y := StrToFloat(Edit2.text); MakeRandom(X,Y); Label3.Caption := floattostrf(MakeRandom(X,Y),fffixed,7,2); end else MessageDlg('Need some values', mtInformation, [mbCancel], 0); end; function MakeRandom(X,Y:Real):real; begin result := x + y*random; {calc value} end; procedure TForm1.FormCreate(Sender: TObject); begin Edit1.Text := ''; Edit2.Text := ''; end; end.

Wed, 18 Jun 1902 08:00:00 GMT 


Page 1 of 2

[ 20 post ] 

Go to page:
[1]
[2] 
