Does RandBetween in microsoft word exist?

Does RandBetween in microsoft word exist?

• jueves, 02 de agosto de 2012 2:11

That's pretty much the question. I'm trying to get a code that chooses a random number between -1 and 1.

• Editado viernes, 03 de agosto de 2012 3:16
•

Todas las respuestas

• jueves, 02 de agosto de 2012 5:22

There is no such function built in, but you can easily create on yourself:

```Function RandBetween(Bottom As Long, Top As Long) As Long
RandBetween = Bottom + Int(Rnd * (Top - Bottom + 1))
End Function```

and use it like the Excel function.

Regards, Hans Vogelaar

• jueves, 02 de agosto de 2012 23:27

i used one from here: http://msdn.microsoft.com/en-us/library/f7s023d2(v=vs.90).aspx

unfortunately, it does nothing for my code.

• Editado viernes, 03 de agosto de 2012 3:16 code is private
•
• viernes, 03 de agosto de 2012 1:51

Try:

Randomize Timer
h = CLng(Int((3 * Rnd()) - 1))

Note that you may get an error if i=1 and h = -1.

Cheers
Paul Edstein
[MS MVP - Word]

• Marcado como respuesta viernes, 03 de agosto de 2012 2:10
•
• viernes, 03 de agosto de 2012 2:10

Try:

Randomize Timer
h = CLng(Int((3 * Rnd()) - 1))

Note that you may get an error if i=1 and h = -1.

Cheers
Paul Edstein
[MS MVP - Word]

that's amazing, how did you know? it worked very well, perfectly and I've been trying for so long too. where's the negative value? so so amazing, thank you so much.
• Marcado como respuesta viernes, 03 de agosto de 2012 2:10
• Desmarcado como respuesta viernes, 03 de agosto de 2012 2:10
•
• viernes, 03 de agosto de 2012 3:41

Hi tonayie,

3 * Rnd() produces a number between 0 and 3.
Int(3 * Rnd())  discards the decimal parts and thus returns 0, 1 or 2
Deducting 1 from 0, 1 or 2 returns -1, 0 or 1.

Quite simple, really.

Cheers
Paul Edstein
[MS MVP - Word]