The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » sci.math.* » sci.math

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Help with algorithm for adjusting RGB colors
Replies: 8   Last Post: Jan 6, 2013 11:25 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Jennifer Murphy

Posts: 24
Registered: 2/23/12
Re: Help with algorithm for adjusting RGB colors
Posted: Jan 5, 2013 3:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Sat, 05 Jan 2013 11:47:09 -0600, David C. Ullrich
<> wrote:

>On Fri, 04 Jan 2013 15:08:19 -0800, Jennifer Murphy
><JenMurphy@jm.invalid> wrote:

>>I have a little Word macro that will assign a random color from the
>>entire 16M color palette to each letter in a text string. It does this
>>by selecting a random number on (0,255) for each of the RGB colors.
>>The VBA code is:
>> Sub MyRandCharColors()
>> Dim oChr As Range
>> Dim sngR As Single, sngG As Single, sngB As Single
>> Randomize

>A comment that has nothing to do with your question:
>That call to Randomize is wrong!

It may not be optimal, but I don't think it's wrong.

>It's a common thing, people calling Randomize, or the
>equivalent in another language, in the body of a
>function like this, thinking that the more calls to
>Randomize the better.

How do you know what "people", or more specifically I, think or why the
call was put where it was? A little presumptuous, don't you think? Also
a little condescending.

In my case, you are incorrect.

>But in fact you should call
>Randomize only _once_ in the course of the application!
>Call Randomize in whatever routine VBA has for
>initializing things (FormCreate or something).
>You think calling Randomize over and over is
>making things more random,

There you go again. How do you know what I think? I do not think that
calling Randomize more than once will somehow (magically) make things
more random.

>but it actually
>makes things _less_ random. The story:
>Randomize sets some "seed" based on the
>system clock. Once that seed is set, repeated
>calls to Rnd return a sequence of quasi-random
>numbers, starting with he seed.

Yes, I knew that, as, I imagine, do most "people".

>Luckily VBA is slow. But the same principle
>applies: Imagine this is some fast compiled
>language. You call Randomize, the seed gets
>set. The next time you call MyRandCharColors,
>the clock hasn't ticked yet, so you reset
>the seed to the same as you set it the
>first time! So your second call to MyRandCharColors
>gives exactly the same colors as the first call.

In this application, that can never happen even if VBA were
instantaneous. Most of the time, I run the marco only once. The only
times that I run it more than once is if I don't like the colors that
result. That takes me at least a few seconds to determine. I'm pretty
sure that the clock is ticking at something like millisecond frequency.

>If you haven't noticed this problem it's because
>VBA is so slow. But regardless, only _one_ call
>to Randomize, at the start of the application,
>will make the colors more random. Honest.

In theory (or principle), I agree with you. In this quick and dirty
application to make multi-colored titles for greeting cards, it makes
absolutely no difference.

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.