Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 48
Default How can I use the same random number twice in the same formula?

I'm trying to use the same random number twice in the same cell formula:
I entered "=TEXT(RANDBETWEEN(1,255),"000 ")&CHAR(RANDBETWEEN(1,255))"
to display both an ASCII number and its character but this generates a
different random number for each "randbetween" instead of the same one. I
could use a helper column but I just wonder if this would somehow be possible
within the same cell.
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 15,768
Default How can I use the same random number twice in the same formula?

If you can download and install the free Morefunc.xll add-in from:

http://xcell05.free.fr/morefunc/english/index.htm

Alternative download site:

http://www.download.com/Morefunc/300...-10423159.html

Then you can use a formula like this:

=TEXT(SETV(RANDBETWEEN(1,255)),"000 ")&CHAR(GETV())

The SETV function creates a static variable generated by the RANDBETWEEN
function and the GETV function retruns that static variable.

So, if RANDBETWEEN returns 76 GETV also returns 76.

--
Biff
Microsoft Excel MVP


"Bob Arnett" wrote in message
...
I'm trying to use the same random number twice in the same cell formula:
I entered "=TEXT(RANDBETWEEN(1,255),"000 ")&CHAR(RANDBETWEEN(1,255))"
to display both an ASCII number and its character but this generates a
different random number for each "randbetween" instead of the same one. I
could use a helper column but I just wonder if this would somehow be
possible
within the same cell.



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,059
Default How can I use the same random number twice in the same formula?

"Bob Arnett" wrote:
this generates a different random number for each "randbetween"
instead of the same one. I could use a helper column


If by "helper column", you mean copy-and-paste-special-value, that is the
only way I know of to "freeze" random values created using the RAND and
RANDBETWEEN functions. They are volatile functions; so by definition, they
change every time there is any change to the workbook :(.


but I just wonder if this would somehow be possible
within the same cell.


You can copy-and-paste-special-value back to the same cell(s). But then you
loose the formula, if/when you want to generate new random values.

Alternatively, I write my own VBA UDF; see below.

Technically, it is not exactly the same since Excel RAND returns a 64-bit
random value, whereas VBA Rnd returns a 32-bit random value. I don't know
which RANDBETWEEN uses. But the form of the random value (64-bit or 32-bit)
does not necessarily determine the "period" of the RNG (i.e. how long before
it repeats itself); and it probably does not matter unless you are
generating millions of random numbers in a single workbook.


Function myRandbetween(low As Double, high As Double) As Double
low = Int(low)
high = Int(high)
myRandbetween = low + Int((high - low + 1) * Rnd)
End Function



"Bob Arnett" wrote in message
...
I'm trying to use the same random number twice in the same cell formula:
I entered "=TEXT(RANDBETWEEN(1,255),"000 ")&CHAR(RANDBETWEEN(1,255))"
to display both an ASCII number and its character but this generates a
different random number for each "randbetween" instead of the same one. I
could use a helper column but I just wonder if this would somehow be
possible
within the same cell.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting random Data created from a random formula Six Sigma Blackbelt Excel Discussion (Misc queries) 1 September 11th 08 11:03 PM
How can I match a random number with closest number from sequence? Matt Excel Worksheet Functions 4 August 3rd 06 01:22 AM
same number appears in a random number generator Carmel Excel Worksheet Functions 4 May 28th 06 12:22 AM
formula that gives me a random number less than other number janiladewilly Excel Worksheet Functions 1 October 13th 05 03:22 AM
How do I find random number in list of random alpha? (Position is. jlahealth-partners Excel Discussion (Misc queries) 0 February 8th 05 05:31 PM


All times are GMT +1. The time now is 09:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"