Random part number

Random part number

am 06.10.2007 00:17:10 von Railman

I need to assign a random number (1000-9999) to each file that is
created. How do I create a field that will generate this number each
time I create a new record. Mac 10.4.9 FM 8.1 Pro.

Re: Random part number

am 06.10.2007 03:42:02 von bill

In article <2007100516171016807-railman@sasktelnet>,
Ron Lambert wrote:

> I need to assign a random number (1000-9999) to each file that is
> created. How do I create a field that will generate this number each
> time I create a new record. Mac 10.4.9 FM 8.1 Pro.

Define a number field to hold the random number. Define it to be filled
by calculation. Use the RAND function in the calculation. When a new
record is created, the field will be filled according to the calculation
formula.

--
For email, change to
Bill Collins

Re: Random part number

am 06.10.2007 04:46:55 von Grip

On Oct 5, 4:17 pm, Ron Lambert wrote:
> I need to assign a random number (1000-9999) to each file that is
> created. How do I create a field that will generate this number each
> time I create a new record. Mac 10.4.9 FM 8.1 Pro.

Do you need the number to be random and unique? Why does it have to
be random...Does it need to be truly random or just random? Truly
random numbers are hard to come by, but unless there's money involved
the Random function does all right.

Re: Random part number

am 06.10.2007 05:41:24 von Railman

On 2007-10-05 20:46:55 -0600, Grip said:

> On Oct 5, 4:17 pm, Ron Lambert wrote:
>> I need to assign a random number (1000-9999) to each file that is
>> created. How do I create a field that will generate this number each
>> time I create a new record. Mac 10.4.9 FM 8.1 Pro.
>
> Do you need the number to be random and unique? Why does it have to
> be random...Does it need to be truly random or just random? Truly
> random numbers are hard to come by, but unless there's money involved
> the Random function does all right.

Yea, the number must be between 1000 and 9999 and unique. I can get
a list of 9999 randomly generated numbers, but the problem is that I
have to select it in sequence from the list -- again a problem I have
not been able to overcome.

It is for a stock control system, were every item that comes in is
given a number unique to that item. I figure that they will never have
more than 8999 items, so this is the number of numbers I need.
Something like an SKU number or each item NOT catagory.

Re: Random part number

am 06.10.2007 06:17:52 von Helpful Harry

In article <2007100516171016807-railman@sasktelnet>, Ron Lambert
wrote:

> I need to assign a random number (1000-9999) to each file that is
> created. How do I create a field that will generate this number each
> time I create a new record. Mac 10.4.9 FM 8.1 Pro.

For each file or each record????

If you mean each record, then that's exactly what the Random function
is for. This function generates a psuedo-random number (no computer
generated number is ever truly random) between 0 and 1.

The standard formula for generating random numbers between a Lower
Limit and an Upper Limit is always:

Lower Limit + (Random * (Upper Limit - Lower Limit))

Note: since the number generated is BETWEEN 0 and 1 you will never
actually get 0 or 1, meaning that the standard forumal itself will
never generate the Upper Limit or Lower Limit number. You get around
this by using the Round function as shown below.


If you multiply the 0 to 1 number generated by the Radnom function by
8999 (ie. 9999 - 1000) you'll get a random number between 0 and 8999,
and if you then add 1000 you get a random number between 1000 and 9999.
Since these are fractional numbers, you'll probably also need the Round
function to remove excess decimal places.

Using this as an Auto-enter by Calculation for a Number field and
you're done.
eg.
RandomNumber Number, Auto-enter by Calculation
= Round(1000 + (Random * 8999), 0)

Using the Round function will make sure that there is a possibility of
generating the Upper Limit and Lower Limit numbers (ie. 1000.2532 is
rounded down to 1000 and 9998.7632 is rounded up to 9999). If, when
dealing with whole numbers, you do not want the Upper Limit and / or
Lower Limit to ever have the possiblity of being generated, then simply
add 1 to them in the standard formula above (remembering that the Lower
Limit appears twice).

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)

Re: Random part number

am 06.10.2007 06:20:32 von Old Foggy

"Helpful Harry" wrote in message
news:061020071617525520%helpful_harry@nom.de.plume.com...
> In article <2007100516171016807-railman@sasktelnet>, Ron Lambert
> wrote:
>
>> I need to assign a random number (1000-9999) to each file that is
>> created. How do I create a field that will generate this number each
>> time I create a new record. Mac 10.4.9 FM 8.1 Pro.
>
> For each file or each record????
>
> If you mean each record, then that's exactly what the Random function
> is for. This function generates a psuedo-random number (no computer
> generated number is ever truly random) between 0 and 1.
>
> The standard formula for generating random numbers between a Lower
> Limit and an Upper Limit is always:
>
> Lower Limit + (Random * (Upper Limit - Lower Limit))
>
> Note: since the number generated is BETWEEN 0 and 1 you will never
> actually get 0 or 1, meaning that the standard forumal itself will
> never generate the Upper Limit or Lower Limit number. You get around
> this by using the Round function as shown below.
>
>
> If you multiply the 0 to 1 number generated by the Radnom function by
> 8999 (ie. 9999 - 1000) you'll get a random number between 0 and 8999,
> and if you then add 1000 you get a random number between 1000 and 9999.
> Since these are fractional numbers, you'll probably also need the Round
> function to remove excess decimal places.
>
> Using this as an Auto-enter by Calculation for a Number field and
> you're done.
> eg.
> RandomNumber Number, Auto-enter by Calculation
> = Round(1000 + (Random * 8999), 0)
>
> Using the Round function will make sure that there is a possibility of
> generating the Upper Limit and Lower Limit numbers (ie. 1000.2532 is
> rounded down to 1000 and 9998.7632 is rounded up to 9999). If, when
> dealing with whole numbers, you do not want the Upper Limit and / or
> Lower Limit to ever have the possiblity of being generated, then simply
> add 1 to them in the standard formula above (remembering that the Lower
> Limit appears twice).
>
> Helpful Harry
> Hopefully helping harassed humans happily handle handiwork hardships
> ;o)

Seems to me if the number must also be unique there has to be a formula
to test if the greneated number has not previously been used.

Gus

Re: Random part number

am 06.10.2007 07:55:02 von Helpful Harry

In article <2007100521412475249-railman@sasktelnet>, Ron Lambert
wrote:

> On 2007-10-05 20:46:55 -0600, Grip said:
>
> > On Oct 5, 4:17 pm, Ron Lambert wrote:
> >> I need to assign a random number (1000-9999) to each file that is
> >> created. How do I create a field that will generate this number each
> >> time I create a new record. Mac 10.4.9 FM 8.1 Pro.
> >
> > Do you need the number to be random and unique? Why does it have to
> > be random...Does it need to be truly random or just random? Truly
> > random numbers are hard to come by, but unless there's money involved
> > the Random function does all right.
>
> Yea, the number must be between 1000 and 9999 and unique. I can get
> a list of 9999 randomly generated numbers, but the problem is that I
> have to select it in sequence from the list -- again a problem I have
> not been able to overcome.
>
> It is for a stock control system, were every item that comes in is
> given a number unique to that item. I figure that they will never have
> more than 8999 items, so this is the number of numbers I need.
> Something like an SKU number or each item NOT catagory.

Ahh, you didn't say it had to be unique.

In this case a random number is a silly way to do it. You should be
using a Serial Number, which is an auto-enter option for any field. You
can start from whatever number you want and FileMaker will
automatically add 1 whenever a record is created.

Helpful Harry
Hopefully helping harassed humans happily handle handiwork hardships ;o)

Re: Random part number

am 06.10.2007 14:22:49 von Grip

On Oct 5, 9:41 pm, Ron Lambert wrote:
> On 2007-10-05 20:46:55 -0600, Grip said:
>
> > On Oct 5, 4:17 pm, Ron Lambert wrote:
> >> I need to assign a random number (1000-9999) to each file that is
> >> created. How do I create a field that will generate this number each
> >> time I create a new record. Mac 10.4.9 FM 8.1 Pro.
>
> > Do you need the number to be random and unique? Why does it have to
> > be random...Does it need to be truly random or just random? Truly
> > random numbers are hard to come by, but unless there's money involved
> > the Random function does all right.
>
> Yea, the number must be between 1000 and 9999 and unique. I can get
> a list of 9999 randomly generated numbers, but the problem is that I
> have to select it in sequence from the list -- again a problem I have
> not been able to overcome.
>
> It is for a stock control system, were every item that comes in is
> given a number unique to that item. I figure that they will never have
> more than 8999 items, so this is the number of numbers I need.
> Something like an SKU number or each item NOT catagory.

So why do the numbers have to be random? Can they be serialized?
There's ways to do what you're asking, but it's easy as 1-2-3 if the
numbers don't have to be random. An Auto Enter Serial Number will
work in the latter case.

G

Re: Random part number

am 07.10.2007 09:48:41 von Sargasso

Ron Lambert wrote:
>I need to assign a random number (1000-9999) to each file that is
>created. How do I create a field that will generate this number each
>time I create a new record. Mac 10.4.9 FM 8.1 Pro.
>

The solution to this is to hold a list of numbers available and remove the
number from the list once it is used. This can be done using a tables, globals
or variables and through relationships, scripting and custom functions.

The easy way is to create a table with a single id field with as many records
as numbers you want to hand out. Create a script to pick a random record, take
its id number for further use and delete the record.

If you really need to do without scripts and or custom functions you can solve
this using a relationship to the id table but it is way more elaborate.

Have fun