Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number Generator


Hello everyone,

I could use some help from y'all. I have a macro that is going to loo
through the range (A1:A100), and use the number in that particular cel
to fill in range(B1:B100) with the corresponding question. Now, what
need help creating, is a random number generator to fill in th
range(A1:A100) with a random number. There are approximately 50
questions that will be available, so I don't want it to use the sam
question twice. How can I create a macro to randomly generate a numbe
from 1 to 500 and enter them into range(A1:A100) and not using the sam
number again...

Any help will be greatly appreciated

--
dok11
-----------------------------------------------------------------------
dok112's Profile: http://www.excelforum.com/member.php...fo&userid=1058
View this thread: http://www.excelforum.com/showthread.php?threadid=48472

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random Number Generator

Sub GenRandom()
With Range("A1:A500")
.Formula = "=Row()"
.Formula = .Value
.Offset(0, 1).Formula = "=rand()"
.Resize(, 2).Sort Key1:=Range("B1"), Header:=xlNo
End With
Columns(2).ClearContents
Range("A101:A500").ClearContents
End Sub



--
Regards,
Tom Ogilvy




"dok112" wrote in
message ...

Hello everyone,

I could use some help from y'all. I have a macro that is going to loop
through the range (A1:A100), and use the number in that particular cell
to fill in range(B1:B100) with the corresponding question. Now, what I
need help creating, is a random number generator to fill in the
range(A1:A100) with a random number. There are approximately 500
questions that will be available, so I don't want it to use the same
question twice. How can I create a macro to randomly generate a number
from 1 to 500 and enter them into range(A1:A100) and not using the same
number again...

Any help will be greatly appreciated.


--
dok112
------------------------------------------------------------------------
dok112's Profile:

http://www.excelforum.com/member.php...o&userid=10581
View this thread: http://www.excelforum.com/showthread...hreadid=484726



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number Generator


Just for academic interest:

Sub Rand100From500()

For Each c In Range("a1:a100")
Do Until Application.CountIf(Range("a1:a100"), c.Value) = 1
c.Value = Int(Rnd * 500 + 1)
Loop
Next

End Sub



David


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=484726

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Random Number Generator

for further academic interest, your method is faster until about 160 numbers
are generated, then my method is faster. At least in my tests.

Obviously the requirement here was for only 100.

--
Regards,
Tom Ogilvy


"davidm" wrote in
message ...

Just for academic interest:

Sub Rand100From500()

For Each c In Range("a1:a100")
Do Until Application.CountIf(Range("a1:a100"), c.Value) = 1
c.Value = Int(Rnd * 500 + 1)
Loop
Next

End Sub



David


--
davidm
------------------------------------------------------------------------
davidm's Profile:

http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=484726



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number Generator


Tom,

For all practical purposes, using random numbers to sort does the jo
but still on the object of academic interest, what happens if th
random numbers generated are *not* 100% unique?

Put another way, if it is -conceivable - that two random number
returned by the RND function could be exactly the same, we can d
violence to the facts and logically assume that in a very very rar
moment of aberration, all the random numbers returned in a range wil
be equal. That being the case, the sorting mechanimsm will b
stullified.

I do concede that the probability of getting 2 random numbers the sam
in a range of 65536 rows should be infinistemally close to zero, an
the Prob(E) of having all 65536 instances even more so. However, fo
as long as Prob(E) <0, we cannot guarantee *100% accuracy* in sortin
-in all cases -and -at all times-. In the context of pure mathematica
accuracy, Randomization could yet fail us.

Food for thought.


Davi

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=48472



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Random Number Generator

davidm wrote:
Tom,

For all practical purposes, using random numbers to sort does the job
but still on the object of academic interest, what happens if the
random numbers generated are *not* 100% unique?

Put another way, if it is -conceivable - that two random numbers
returned by the RND function could be exactly the same, we can do
violence to the facts and logically assume that in a very very rare
moment of aberration, all the random numbers returned in a range will
be equal. That being the case, the sorting mechanimsm will be
stullified.

I do concede that the probability of getting 2 random numbers the same
in a range of 65536 rows should be infinistemally close to zero, and
the Prob(E) of having all 65536 instances even more so. However, for
as long as Prob(E) <0, we cannot guarantee *100% accuracy* in sorting
-in all cases -and -at all times-. In the context of pure mathematical
accuracy, Randomization could yet fail us.

Food for thought.


David


-----------------

Why does it matter? You do the sort on the "random" numbers and it still puts
the other column into some unique order without repeats.

Bill
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Random Number Generator


Bill wrote:

< You do the sort on the "random" numbers and it still puts
<the other column into *some unique order *without repeats.


You miss the point, Bill. In the weirdest extreme when all "random
numbers are equal, sorting for, say, 100 numbers from 1-500 (as in th
original request) will merely return the serial numbers 1-100. Whic
technically is a sample but arguably not a desirable one. Representin
a varying ascending degree of imperfection, notice that there are myria
scenarios between (1) the case of having only 2 repeats in a range t
(2) the case of having of all "random" values in a range equal.

The whole issue is of course purely academic and in all likelihood, i
you were to generate 65536 random numbers a million times, there is
good chance that you would end up with 65536 * 1 million unique sets o
random numbers!

David

--
david
-----------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...fo&userid=2064
View this thread: http://www.excelforum.com/showthread.php?threadid=48472

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Random Number Generator

davidm wrote:
Bill wrote:

< You do the sort on the "random" numbers and it still puts
<the other column into *some unique order *without repeats.


You miss the point, Bill. In the weirdest extreme when all "random"
numbers are equal, sorting for, say, 100 numbers from 1-500 (as in the
original request) will merely return the serial numbers 1-100. Which
technically is a sample but arguably not a desirable one. Representing
a varying ascending degree of imperfection, notice that there are myriad
scenarios between (1) the case of having only 2 repeats in a range to
(2) the case of having of all "random" values in a range equal.

The whole issue is of course purely academic and in all likelihood, if
you were to generate 65536 random numbers a million times, there is a
good chance that you would end up with 65536 * 1 million unique sets of
random numbers!

David.


-----------------

Actually, I think you missed the point...

If you accept your initial premise that Excel has randomly picked all 100
numbers at identical values (one in a zillion chance), then it is equally true
that the end result of having all the sorted numbers in consecutive order is
also a valid random result (one in a zillion chance).

Note that the task is to set a random order, not a "desirable" one.

Bill
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
Random number generator deelee Excel Worksheet Functions 3 October 12th 06 07:46 PM
Random Number Generator STEVEB Excel Worksheet Functions 7 July 25th 05 11:41 PM
random number generator Jose Luis Excel Discussion (Misc queries) 1 June 14th 05 09:41 PM
random number generator rsankh Excel Programming 2 June 5th 05 11:46 AM
Random number generator Philippe L. Balmanno Excel Worksheet Functions 4 December 17th 04 07:42 AM


All times are GMT +1. The time now is 09:00 AM.

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"