Help with pulling randomized data from script

I have managed to get a randomized function working via a script on an event. 

I wanted to have a chest that pulls from the list of items randomly. 

I run this script at the beginning of the event.

var weapon = Math.floor(Math.random() * (3 - 1 + 1)) + 1

$gameParty.gainItem($dataWeapons[weapon],1);

That will give me a weapon randomly from Weapon ID's 1-3.

I am now trying to get the message dialogue to reflect the item that I had received randomly, but I am unsure how to get the two to communicate.

Any scripters know how I could get the random number that I pulled to be inserted into Yanfly's Message core so that I can have the message box say

You have found \iw[weapon]!

Where weapon was the number pulled from that script and needs to be recognized in the Message Core Script.

I am new at scripting and just understand the basics so what I am asking may not be possible with my setup.

 
Why do you do this:

(3 - 1 + 1)? That's ALWAYS going to evaluate to 3.Something like this:

Code:
var weapon = Math.floor(Math.random() * 3) + 1$gameParty.gainItem($dataWeapons[weapon], 1);$gameVariables[1] = $dataWeapons[weapon].name
and then use \V[1] in the message box.
I wasn't sure about that random math code. I just pulled it off google and it worked, but now that I look at, you are right. I have fixed that.

I have tried this script and the message box just returns 0.

I turned Message Core off and tried it and still got 0. I tried switching the variable number and I still get 0.

I am typing "You got \V[1]!!" in the message box. 

I can understand why this should work, so I may be able to fool around with this and figure it out.

Thanks for the help.
I have found the answer.

var weapon = Math.floor(Math.random() * 3) + 1

$gameParty.gainItem($dataWeapons[weapon], 1);

$gameVariables.setValue(1, $dataWeapons[weapon].name) 

This works!!

Thanks for pointing me in the right direction!
ah yeah - I keep forgetting that about $gameVariables. It's gonna take a while before I can keep Ace and MV entirely separate.

Original thread: https://forums.rpgmakerweb.com/threads/help-with-pulling-randomized-data-from-script.49121/