is this a bug?

so i'm developing a plugin to show a user's geolocation (city/region) but before that, i created a metadata that randomly spits out a random number between 1-100. so each wire post has a random number with the wire post's guid. i'm not sure if this is a bug but here's the screen shot

image

basically when i post a new wire post, it shows the guid but not the random number that's supposed to be generated with it. here's the weird part, when i click refresh, the random number shows up! i'm not sure if this is a bug or my coding is off. here's the code i used to create and read metadata

to create a metadata that's post specific on a user's wire, i did:

$value = (rand(1,100)); 
$post->random = $value;

then to read the metadata, i used:

$random = get_metadata_byname($post->guid,'random');
echo $random->value;

 i put this code in views / default / object / thewire.php, not sure if this is a bug or i put the code in the wrong php file but your input could be useful. let me know if it's my coding or it's just elgg. thank you for your time